-
MissingInteger알고리즘/Codility 2020. 9. 13. 21:32
이 문제는 내가 푼 답이 맞긴 했지만, 답 확인 할때 시간이 오래걸려서 통과 하지 못했었다.
결국 다른 사람의 풀이를 보고 통과할 수 있었는데 정말 어떻게 이렇게 생각해서 푸는지 다양한 문제를 더 많이 풀어봐야겠다ㅠㅠ
https://app.codility.com/demo/results/trainingDZ8W4Q-Z7Y/
Test results - Codility
A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The
app.codility.com
문제)
해답) 진짜 깔끔하게 잘한거같다.
public int solution(int[] A) { boolean checker[] = new boolean[A.length + 1]; for(int i = 0 ; i < A.length ; i++){ int value = A[i]; if(value > 0 && value < checker.length){ checker[value] = true; } } for(int i = 1 ; i < checker.length ; i++){ if(checker[i] == false){ return i; } } return checker.length; }
'알고리즘 > Codility' 카테고리의 다른 글
CyclicRotation (0) 2020.09.13 BinaryGap (0) 2020.09.13