Skip to content

Instantly share code, notes, and snippets.

@adamkorg
Created April 7, 2020 10:02
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/e27a11403f0ad938e558f48c31508b52 to your computer and use it in GitHub Desktop.
Save adamkorg/e27a11403f0ad938e558f48c31508b52 to your computer and use it in GitHub Desktop.
Leetcode 274: H-Index
#include <iostream>
#include <vector>
using namespace std;
int hIndex(vector<int>& citations) {
sort(citations.begin(), citations.end(), greater<int>());
int h = 0;
for (int i=0; i<citations.size(); ++i) {
if (citations[i] > i) h=i+1;
else break;
}
return h;
}
int main() {
vector<int> citations {2,6,9,8,1,7}; //{3,0,6,1,5};
cout << hIndex(citations) << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment