Leetcode 275: H-Index II
Follow up for H-Index: What if the citations
array is sorted in ascending order? Could you optimize your algorithm?
1 public class Solution { 2 public int HIndex(int[] citations) { 3 int len = citations.Length; 4 5 for (int i = 0; i < citations.Length; i++) 6 { 7 if (citations[i] >= len) 8 { 9 break; 10 } 11 else 12 { 13 len--; 14 } 15 } 16 17 return len; 18 } 19 }