Codility (5) 썸네일형 리스트형 FlogJump 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // you can also use imports, for example: // import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int solution(int X, int Y, int D) { // write your code in Java SE 8 if ((Y-X)%D == 0) return ((Y-X)/D); else return ((Y-X)/D) + 1; } } http://colorscripter.com/info#e" ta.. TapeEquilibrium 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 // you can also use imports, for example: // import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int solution(int[] A) { // write your code in Java SE 8 int total = 0; for (int i = 0; i OddOccurencesInArray 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // you can also use imports, for example: import java.util.*; // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { public int solution(int[] A) { // write your code in Java SE 8 if (A.length == 1 ) return A[0]; Arrays.sort(A); //[2,2,2,4,5,5,4]-> 2,2.. Cyclic Rotation 두 가지 방법으로 풀 수 있다. (deque(덱), 배열을 하나씩 뒤로 밀고 맨 앞으로 맨 뒤의 요소를 삽입하는 것( O(k*n)) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import java.util.Deque; import java.util.ArrayDeque; import java.util.Iterator; class Solution { public int[] solution(int[] A, int k) { // write your code in Java SE 8 Deque dq = new ArrayDeque(); for (int i = 0; i 0) { if (dq.size() > 0) { dq.addF.. Binary Gap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 class Solution { public int solution(int N) { // write your code in Java SE 8 boolean flag = false; int len = 0, max_len = 0; while(N > 0) { int binary = N % 2; if (binary == 1) { if (!flag) { flag = true; } else { //뒤쪽의 1을 만남 max_len = max_len 이전 1 다음