Java O(nlogn), O(1) solution


  • 0
    D
    public int hIndex(int[] citations) {
            if (citations.length == 0) return 0;
            
            Arrays.sort(citations);
            int thresholdValue = 1;
            int hIndex = 0;
            for (int i = citations.length - 1; i >= 0; i--) {
                if (citations[i] >= thresholdValue) {
                    hIndex++;
                    thresholdValue++;
                } else {
                    break;
                }
            }
            
            return hIndex;
        }
    

  • 0
    J

    If you sort the array , the time complexity should be O(nlogn)


  • 0
    D

    @JDIJason Good catch, my fault


Log in to reply
 

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