내 답안
class Solution {
public int solution(int[] arr, int idx) {
int answer = 0;
for (int i = 0; i < arr.length; i++) {
if (i >= idx && arr[i] == 1) {
answer = i;
break;
} else {
answer = -1;
}
}
return answer;
}
}
Java
복사
다른사람 풀이
import java.util.stream.IntStream;
class Solution {
public int solution(int[] arr, int idx) {
return IntStream.range(idx, arr.length).filter(i -> arr[i] == 1).findFirst().orElse(-1);
}
}
Java
복사