My Java Solution


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

Log in to reply
 

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