1 2 3 4 5 6 7 8 9 10 11 | public class Solution { public int hIndex(int[] citations) { if (citations == null || citations.length == 0) return 0; int[] copy = Arrays.copyOf(citations, citations.length); Arrays.sort(copy); for (int i = copy.length-1, j = 0; i >=0; i--, j++){ if (j>=copy[i]) return j; } return copy.length; } } |
No comments:
Post a Comment