( https://app.codility.com/programmers/lessons/3-time_complexity/tape_equilibrium/ ) Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|. 내 초기 풀이 1) P를 기준으로 왼쪽합을 구하고 (첫 번째 for문) 2) P를 기준으로 오른쪽합을 구하고 (두 번째 for문) 3) 왼쪽합과 오른쪽합을 뺀 후, 절대값 처리를 해주고 4) 왼쪽합 - 오른쪽합들을 계속 비교하여 min함수에 저장 후 반환 이런 식으로 풀었지만 점수는 15점.. 그리고 또 이중 for문을 사용하는 함정에 걸림. class Solution { public int solution(int[] A) { int ..
( https://app.codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/ ) Find the missing element in a given permutation. 내풀이 - 일반적인 테스트는 통과했지만, - 세부적인 테스트에서 에러가 많이 발생. - 앞으로 문제 풀 때는, 0이나 single number처리에 주의해야 한다. public static int solution(int[] A) { int answer = 0; Arrays.sort(A); for (int i = 0; i < A.length; i++){ if (A[i] != i + 1){ answer = i + 1; } } return answer; } 베스트 코드 -..
( https://app.codility.com/demo/results/trainingNFYT4W-93F/ ) Count minimal number of jumps from position X to Y. 내 코드 public class FrogJmp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int X = sc.nextInt(); int Y = sc.nextInt(); int D = sc.nextInt(); System.out.println(solution(X, Y, D)); } public static int solution(int X, int Y, int D) { if ( X == Y){ return ..
( https://app.codility.com/programmers/lessons/2-arrays/odd_occurrences_in_array/ ) 문제링크. If문으로 풀다가, 시간복잡도 측면에서도 그렇고, 이렇게 풀면 안될 것같았음. 따라서 다른사람의 풀이를 분석. - XOR연산풀이. public class OddOccurrencesInArray { public static void main(String[] args) { int[] arr = {9, 4, 9, 4, 7, 9, 9, 4, 4}; System.out.println(solution(arr)); } public static int solution(int[] A) { int answer = 0; for(int num : A) { answer..
- chapter7
- 20200804
- 20200415
- 20200622
- 20200510
- 20200429
- 20200624
- 20200502
- 20200330
- 20200406
- 20200427
- 20200421
- 20200424
- likelion
- 20200413
- 생활코딩리눅스
- chapter8
- 20201204
- 20200425
- 20200319
- 20200512
- 20200428
- 20200417
- 20200503
- 백준
- 20200403
- 20200504
- 20200420
- 20200317
- 20200423
- Total
- Today
- Yesterday