275. H-Index II

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     }

 相关题目:

274. H-Index

posted @ 2017-10-24 15:43  daniel456  阅读(195)  评论(0编辑  收藏  举报