H-Index

JJW·2024년 12월 13일

코딩 테스트

목록 보기
2/23

문제

  • 정렬 > H-Index

문제 풀이

using System;
using System.Linq;

public class Solution 
{
    public int solution(int[] citations) 
    {
        // 인용 횟수
        int hIndex = 0;
        
        // 내림차 순 정렬
        Array.Sort(citations,(x,y) => y.CompareTo(x));
        
        for(int i = 0; i < citations.Length; i++)
        {
        	// 높은 숫자부터 검사하므로
            // ex) 6 >= 0 + 1 = true, 5 >= 1+1 = true, 3 >= 2+1 = true
            //     1 >= 3 +1 = false;
            if(citations[i] >= i + 1)
                hIndex++;
            else
                break;
        }
        
        return hIndex;
    }
}

느낀 점

Unity C#만 사용하다 일반 C#을 통해 구현하려니 익숙치 않습니다..

profile
Unity 게임 개발자를 준비하는 취업준비생입니다..

0개의 댓글