인프런 커뮤니티 질문&답변
컴파일 에러가 발생합니다.
작성
·
259
0
인텔리제이에서 돌릴때는 문제없이 돌아가는데 채점 사이트에서 컴파일 에러가 발생합니다. 왜이런가요?
public class b_01 {
public ArrayList<Integer> solution(int i, int arr[]){
ArrayList<Integer> answer = new ArrayList<>();
answer.add(arr[0]);
for(int a =1; a<i; a++){
if(arr[a]>arr[a-1]) answer.add(arr[a]);
}
return answer;
}
public static void main(String args[]){
b_01 b = new b_01();
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
int arr[] = new int[i];
for(int a = 0; a < i; a++){
arr[a] = sc.nextInt();
}
for(int x : b.solution(i,arr)){
System.out.print(x+" ");
}
}
}
퀴즈
앞에 있는 모든 학생보다 키가 커야 보이는 '보이는 학생' 문제에서, 효율적인 풀이법의 핵심 아이디어는 무엇일까요?
모든 학생의 키를 서로 비교한다.
현재까지 본 학생 중 가장 큰 키를 추적한다.
가장 큰 학생 한 명만 찾는다.
학생들의 키를 오름차순으로 정렬한다.





