본문 바로가기

코딜리티

[코딜리티] - Lesson 3. FrogJmp 안녕하세요 남갯입니다. public class FrogJump { public static int solution(int X, int Y, int D) { // write your code in Java SE 8 int offset = 0; if ((Y - X) % D > 0) { offset = 1; } return (Y == X) ? 0 : (((Y - X) / D) + offset); } }
[코딜리티] - Lesson 2. CyclicRotation 안녕하세요 남갯입니다. Lesson 2. CyclicRotation public int[] solution(int[] A, int K) { // write your code in Java SE 8 if(A.length == 0 || K == A.length || K == 0){ return A; } if(K > A.length){ K %= A.length; } int[] result = new int[A.length]; int idx = 0; for (int i = A.length - 1; i > A.length - K - 1; i--) { result[K- idx -1] = A[i]; idx++; } int d = idx; for (int i = 0; i < A.length - d; i++) { res..
[코딜리티] - Lesson 2. OddOccurrencesInArray - 1 안녕하세요 남갯입니다. lesson 2 안드로이드에 SparseBooleanArray 관련 코드가 있다 저게 더 효율이 있다고 하니 확인해보도록 하자 import android.util.SparseBooleanArray; import java.util.HashMap; import java.util.Map; public class OddOccurrencesInArray { /*// 홀수개 찾기// android public int solution(int[] A) { // write your code in Java SE 8 SparseBooleanArray sparseArray = new SparseBooleanArray(); for (int idx = 0; idx < A.length; idx++) { //..
[코딜리티] - Lesson 1. BinaryGap public class Binary { public int solution(int N) { String binary = Integer.toBinaryString(N); int result = 0; int temp = 0; //1001 = 2 for (char b : binary.toCharArray()) { //b == '1' if (b == '1') { if (temp >= result) { result = temp; } temp = 0; } //b == '0' else { temp++; } } return result; } }