File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 11// Source : https://leetcode.com/problems/h_index/
2- // Author : Calinescu Valentin
2+ // Author : Calinescu Valentin, Hao Chen
33// Date : 2015-10-22
44
55/* **************************************************************************************
4141class Solution {
4242public:
4343 int hIndex (vector<int >& citations) {
44+ return hIndex02 (citations);
45+ return hIndex01 (citations);
46+ }
47+ int hIndex01 (vector<int >& citations) {
4448 sort (citations.begin (), citations.end ());
4549 int h_index = 0 ;
4650 for (int i = citations.size () - 1 ; i >= 0 ; i--)
4751 if (citations[i] >= citations.size () - i && (i - 1 < 0 || citations[i - 1 ] <= citations.size () - i))
4852 h_index = citations.size () - i;
4953 return h_index;
5054 }
55+
56+ // same solution but a bit different implemtation
57+ int hIndex02 (vector<int >& citations) {
58+ sort (citations.begin (), citations.end ());
59+ int n = citations.size ();
60+ for (int i=0 ; i<n; i++){
61+ if (citations[i] >= n-i){
62+ return n-i;
63+ }
64+ }
65+ return 0 ;
66+ }
67+
5168};
You can’t perform that action at this time.
0 commit comments