✔️나의 답 -> 맞음
import java.util.*;
public class p2_1 {
public static String solution(int n , int[] arr) {
String answer =Integer.toString(arr[0])+" ";
for(int i=1;i<n;i++) {
if(arr[i]>arr[i-1]) answer+=Integer.toString(arr[i])+" ";
}
return answer;
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int arr[]= new int[n];
for(int i=0;i<n;i++) {
int n_index=kb.nextInt();
arr[i]=n_index;
}
System.out.printf(solution(n,arr));
}
}
✔️ 강의와 답이 같음