straightforward java solution


  • 0
    Z
    public int hIndex(int[] citations) {
            if(citations.length == 1)return citations[0] >= 1 ? 1 : 0;
            Arrays.sort(citations);
            int res = 0;
            for(int i=0;i<citations.length;i++){
                if(citations[i] > citations.length-i){
                    res = Math.max(res,citations.length-i);
                }else{
                    res = Math.max(res,citations[i]);
                }
            }
            return res;
        }
    

Log in to reply
 

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