```
int hIndex(vector<int>& citations) {
int i = 0, len = citations.size();
for (; i < len && citations[len-i-1] >= i+1; ++i);
return i;
}
```

```
int hIndex(vector<int>& citations) {
int lo = 0, hi = citations.size(), len = citations.size();
while (lo < hi) {
int mid = lo + (hi-lo) / 2;
if (citations[len - mid - 1] >= mid + 1) lo = mid + 1;
else hi = mid;
}
return lo;
}
```