일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 백준 16927
- java 올림
- 백준 18290
- 백준 16935
- 0으로 채우기
- 알고리즘
- 프로그래머스 도둑질 java
- Algorithm
- Codility
- sort
- 백준 17425
- Math.floor()
- 자바
- 코딩테스트
- time complexity
- java
- 프로그래머스 옹알이 java
- 프로그래머스 숫자의 표현 java
- 백준 11723
- 백준 15661
- 백준 4375
- 프로그래머스 연속된 수의 합 java
- java 반올림
- 프로그래머스 네트워크 java
- 네트워크
- java 내림
- Arrays
- mysql
- 백준 14391
- Math.ceil()
- Today
- Total
목록Algorithm/Codility (7)
취미처럼
배열A에서 1부터 정수X까지 모두 나타나는 가장 빠른 차수 찾기 import java.util.HashSet; import java.util.Set; class Solution { public int solution(int X, int[] A) { Set set = new HashSet(); for (int i = 1; i
배열에는 첫 번째 파트와 두 번째 파트가 있다. 0부터 배열의 차수까지가 첫번째 파트, 그 다음부터 마지막까지가 두번째 파트이다. 첫번째 파트에서 두번째 파트를 마이너스 한 값의 절대값 중에서 최소값을 구한다. int[] A = {1,2,3,4,5}; 0차 (1) - (2 + 3 + 4 + 5) = |-13| 1차 (1 + 2) - (3 + 4 + 5) = |-9| 2차 (1 + 2 + 3) - (4 + 5) = |-3| 3차 (1 + 2 + 3 + 4) - (5) = |5| public int solution(int[] A) { int total = 0; int first = 0; int second = 0; int min = Integer.MAX_VALUE; for (int i = 0; i < A.l..
1부터 N개의 서로 다른 정수로 이루어진 배열에서 누락된 하나의 요소 찾기 import java.util.Arrays; class Solution { public int solution(int[] A) { Arrays.sort(A); for (int i = 0; i < A.length; i++) { if (i + 1 != A[i]) { return i + 1; } } return A.length + 1; } }
고정값 D만큼 이동하여 X에서 Y까지 도달할 수 있는 최소 수행값 public int solution(int X, int Y, int D) { int distance = Y - X; return distance % D == 0 ? distance / D : distance / D + 1; }
배열 중 같은 수로써 짝이 맞지 않는 요소를 구하는 문제 public int solution(int[] A) { int answer = 0; for (int i = 0; i < A.length; i++) { answer ^= A[i]; } return answer; } XOR 연산은 같은 수일 때 0을 리턴한다.
주어진 배열 A에서 정수 K만큼 배열의 차수를 올리되, 차수가 배열 길이 이상일 때 0부터 다시 시작한다. public static int[] solution(int[] A, int K) { int answer[] = new int[A.length]; for (int i = 0; i < A.length; i++) { answer[(i + K) % A.length] = A[i]; } return answer; } int[] A = {0,3,4,2,5}; int K = 3; answer 배열의 인덱스 (0 + 3) % 5 = 3 answer[3] = A[0]; (1 + 3) % 5 = 4 answer[4] = A[1]; (2 + 3) % 5 = 0 answer[0] = A[2]; (3 + 3) % 5 = 1..
2진수의 1과 1사이의 간격 중 가장 큰 값을 찾는 문제 public static int solution(int N) { String str = Integer.toBinaryString(N); String[] arr = str.split(""); int totalGapLength = 0; int gapLength = 0; for (int i = 0; i totalGapLength) { totalGapLength = gapLength; } gapLength = 0; } else if(arr[i].equals("0")) { gapLength++; } } return totalGapLength; }