Skip to content

Commit

Permalink
Create h-index.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Sep 3, 2015
1 parent 0bff912 commit bc7c328
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions C++/h-index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Time: O(nlogn)
// Space: O(1)

class Solution {
public:
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 + 1) {
++h;
} else {
break;
}
}
return h;
}
};

0 comments on commit bc7c328

Please sign in to comment.