-
MaxCountersStudy/알고리즘 2018. 1. 12. 11:33
첫 난이도 Easy가 아닌 문제
이런문제가 더 재밋다. 뭔가 진짜 푸는듯한 느낌
public static int[] solution(int N, int[] A){ int answer[] = new int[N]; // A Scan for(int i = 0; i < A.length ; i++){ //increase or max 할지 체크 if(A[i] >= 1 && A[i] <= N){ //increase answer[A[i]-1] += 1; }else if(A[i] == N+1){ //Max // answer 배열의 맥스값을 찾는다 int max = 0; for(int n : answer){ if(n > max){ max = n; } } //answer 배열을 max값으로 치환한다. for(int j = 0 ; j < answer.length ; j++){ answer[j] = max; } } // for(int n : answer){ // System.out.print(n +" ,"); // } // System.out.println(); } return answer; }
'Study > 알고리즘' 카테고리의 다른 글
Triangle (0) 2018.01.15 MinAvgTwoSlice (0) 2018.01.15 GenomicRangeQuery (0) 2018.01.15 PassingCars (0) 2018.01.12 CountDiv (0) 2018.01.12 MissingInteger (0) 2018.01.12 FrogRiverOne (0) 2018.01.12 PermCheck (0) 2018.01.11 PermMissingElem (0) 2018.01.11 FrogJmp (0) 2018.01.11