Easy solution based on Java---Just One Pass


  • 0
    S
    public class Solution {
        public int hIndex(int[] citations) {
            if(citations.length==0)return 0;
            Arrays.sort(citations);
            int l=citations.length;
            int cit=citations[l-1],h=0;
            int i;
            for(i=l-1;h<cit&&i>=0;--i){
                cit=citations[i];
                h++;
            }
            if(h>=cit)return Math.max(cit,h-1);
            else return h;
        }
    }
    

Log in to reply
 

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