CS/Algorism

99클럽 코테 스터디 26일차 TIL: [LeetCode] 275. H-Index II

olsohee 2024. 6. 14. 11:57

https://leetcode.com/problems/h-index-ii/description/

 

class Solution {
    public int hIndex(int[] citations) {
        int n = citations.length;
        int start = 0;
        int end = n-1;

        while(start <= end){
            int mid = start + (end - start)/2;
            if(citations[mid] < n - mid){
                start = mid+1;
            }else {
                end = mid-1;
            }
        }

        return n-start;
    }
}