본문 바로가기

IT/알고리즘

[코딜리티] - Lesson 4. FrogRiverOne

SMALL

안녕하세요 남갯입니다.




public class FrogRiverOne {

public static int solution(int X, int[] A) {
int sum = ((X) * (X + 1)) / 2;
int result = -1;
Map<Integer, Boolean> map = new HashMap<>();
if(A.length == 0){
return -1;
}
int i = 0;
for (int a : A) {
if (!map.containsKey(a)) {
map.put(a, true);
sum -= a;
}

if (sum == 0) {
return i;
}
i++;
}
return result;
}
}


https://app.codility.com/demo/results/trainingZYBBSY-F3V/

LIST