Lewis's Tech Keep

[프로그래머스] H-Index 본문

JAVA/알고리즘

[프로그래머스] H-Index

Lewis Seo 2021. 2. 3. 01:53

정렬 방법에 관한 문제

 

 - number -> string으로 바꿔서 바꾼 값을 다시 o1 + o2 , o2 + o1 과 비교가 가능한 지 생각했다면 빠르게 풀 수 있었던 문제

 

  - 생각보다 시간이 조금 걸렸다. (설명을 잘 못 읽어서..)

 

  - 문제를 좀 더 잘 이해할 수 있다면 좀 더 빨리 끝낼 수 있을 것이다.

 

 

더보기
class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        int max = 0;
        for(int num: citations) {
            if(max < num) {
                max = num;
            }
        }
        
        for(int i=max; i> 0; i--) {
            int overCount = 0;
            for(int num: citations) {
                if(num >= i) {
                    overCount++;
                }
            }
            if(i <= overCount) {
                answer = i;
                break;
            }
        }
        
        return answer;
    }
}
Comments