Share My O(log(n)) Solution


  • 0
    C
    public class Solution {
      public int hIndex(int[] citations) {
        if (citations.length == 0) {
            return 0;
        }
        int begin = 0;
        int end = citations.length - 1;
        while (begin < end) {
            int mid = (begin + end) / 2;
            if (citations[mid] < citations.length - mid) {
                begin = mid + 1;
            } else {
                end = mid;
            }
        }
        
        return citations[begin] < citations.length - begin ? 0 : citations.length - begin;
     }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.