코딩 테스트/Codility

    코딜리티 - TapeEquilibrium 문제 (자바)

    app.codility.com/programmers/lessons/3-time_complexity/ 3. Time Complexity lesson - Learn to Code - Codility Count minimal number of jumps from position X to Y. app.codility.com 앞에서 부터 더한 누적값 배열을 만들고 뒤에서 부터 더한 누적값 배열을 만들어서 두 배열의 일정 위치의 값을 빼고 절대값으로 하여 작은 값을 구함 // 코딜리티 - TapeEquilibrium 문제 class TapeEquilibrium { public int solution(int[] A) { // write your code in Java SE 8 int length = A.length;..

    코딜리티 - PermMissingElem 문제 (자바)

    app.codility.com/programmers/lessons/3-time_complexity/ 3. Time Complexity lesson - Learn to Code - Codility Count minimal number of jumps from position X to Y. app.codility.com 정렬 후 값을 인덱스와 인덱스 + 1을 비교한다. 만약 전부 같으면 N+1이 없는 것이므로 N + 1을 리턴한다. import java.util.Arrays; // 코딜리티 - PermMissingElem 문제 class PermMissingElem { public int solution(int[] A) { // write your code in Java SE 8 Arrays.sort(A);..

    코딜리티 - FlogJump 문제 (자바)

    app.codility.com/programmers/lessons/3-time_complexity/ 3. Time Complexity lesson - Learn to Code - Codility Count minimal number of jumps from position X to Y. app.codility.com 목적지인 Y에서 현재위치 X를 빼면 개구리가 가야하는거리가 나오고 이 거리를 개구리의 고정 이동 거리 D로 나누고 나머지가 있는경우 +1 해서 해결 // 코딜리티 - FlogJump 문제 class FlogJump { public int solution(int X, int Y, int D) { // write your code in Java SE 8 int distance = Y - X; i..

    코딜리티 - OddOccurrencesInArray 문제 (자바)

    app.codility.com/programmers/lessons/2-arrays/ 2. Arrays lesson - Learn to Code - Codility Rotate an array to the right by a given number of steps. app.codility.com 배열을 정렬하고 짝수번째 값을 더하고 홀수먼째 값은 빼면 결과가 나온다 예로 4 2 4 1 2 3 1 이런 배열을 정렬하면 1 1 2 2 3 4 4 이런 배열이 되고 result = result + 1 - 1 + 2 - 2 + 3 - 4 + 4; -> 3 리턴 import java.util.Arrays; // 코딜리티 - OddOccurrencesInArray 문제 class OddOccurrencesInArray..

    코딜리티 - CyclicRotation 문제 (자바)

    app.codility.com/programmers/lessons/2-arrays/ 2. Arrays lesson - Learn to Code - Codility Rotate an array to the right by a given number of steps. app.codility.com 만약 K가 4이고 배열의 크기도 K라면 다돌고난 뒤와 돌기전이 동일하다. K를 배열의 크기로 나눈 나머지만큼 이동하면된다. // 코딜리티 - CyclicRotation 문제 class CyclicRotation { public int[] solution(int[] A, int K) { // write your code in Java SE 8 int[] result = new int[A.length]; for(int..

    코딜리티 - BinaryGap 문제 (자바)

    app.codility.com/programmers/lessons/1-iterations/ 1. Iterations lesson - Learn to Code - Codility Find longest sequence of zeros in binary representation of an integer. app.codility.com 숫자를 2이진법 문자로 변경한 뒤 두번째 문자부터 0이면 세고 1이면 센값을 max와 비교하여 답을 구함. 2진법으로 변경하면 맨앞으로 숫자는 1이므로 그다음부터 체크한다. // 코딜리티 - BinaryGap 문제 class BinaryGap { public int solution(int N) { int result = 0; int count = 0; String str = ..