Skip to content

Instantly share code, notes, and snippets.

@adamkorg
Created April 11, 2020 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamkorg/7ba2ca2a0f4ed09df59401e4dc3fc439 to your computer and use it in GitHub Desktop.
Save adamkorg/7ba2ca2a0f4ed09df59401e4dc3fc439 to your computer and use it in GitHub Desktop.
Leetcode 275: H-Index II (linear)
#include <iostream>
#include <vector>
using namespace std;
int hIndex(vector<int>& citations) {
int h=0, len=citations.size();
for (int i=len-1; i>=0; --i) {
if (citations[i] >= len-i) h++;
else break;
}
return h;
}
int main() {
vector<int> citations {0,1,3,5,6};
cout << hIndex(citations) << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment