题目:
Follow up for H-Index: What if the citations
array is sorted in ascending order? Could you optimize your algorithm?
分析:
没啥想说的。
代码:
class Solution {
public:
int hIndex(vector<int>& citations) {
int h=0;
for(int i=citations.size()-1;i>=0;--i){
if(h>=citations[i])return h;
h++;
}
return h;
}
};