Follow up for H-Index: What if the citations
array is sorted in ascending order? Could you optimize your algorithm?
题目含义:给定的数组是有序的,再次找h值
1 public int hIndex(int[] citations) { 2 int left=0,right=citations.length-1; 3 while (left<right) 4 { 5 int temp = citations[left]; 6 citations[left] = citations[right]; 7 citations[right] = temp; 8 left++;right--; 9 } 10 for (int i = 0; i < citations.length; ++i) { 11 if (i >= citations[i]) return i; 12 } 13 return citations.length; 14 }
相关题目: