Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
Show Hint
public class Solution {
public int hIndex(int[] citations) {
if(citations == null || citations.length == 0){
return 0;
}
int ans = citations.length;
for(int i = 0; i < citations.length; ++i){
if(citations[i] >= ans){
return ans;
}else{
ans--;
}
}
return 0;
}
}