Simple 3 ms solution in java


  • 0
    R
    public class Solution {
    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int max = 0;
        for(int i = citations.length - 1; i >= 0; i--){
            int j = citations.length - i;
            int toCompare = Math.min(j, citations[i]);
            max = Math.max(max, toCompare);
        }
        return max;
    }
    }

Log in to reply
 

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