알고리즘/Codility
-
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 ..
-
CyclicRotation알고리즘/Codility 2020. 9. 13. 21:24
app.codility.com/demo/results/training8K9DTZ-447/ Test results - Codility An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, app.codility.com 문제) 배열 A의 값을 K만큼 우측으로 이동시켜 출력. 마지막 배열의 값은 배열의 첫번째로..
-
BinaryGap알고리즘/Codility 2020. 9. 13. 21:13
문제) 정수 N에서 binaryGap의 최댓값을 찾아라. binaryGap이란 1로 둘러쌓인 0의 개수로, 예) N이 529일때, 2진수로는 1000010001 이때, binaryGap의 최댓값은 4. binaryGap이 없으면 return -1; 나의 해답 import java.util.*; class Solution { public int solution(int N) { int answer = 0; if(N == 1 || N == 0){ return answer; } int mok = 0; List list = new ArrayList(); while (mok != 1) { mok = (N / 2); list.add((N % 2)); if (mok == 1) { list.add(mok); } N = ..