Given an array of citations (each citation was a non-negative integer) of a researcher, write a function to compute the RES Earcher ' s h-index.
According to the definition of H-index on Wikipedia: ' A scientist has index H if h of his/her N Papers has at least H citations each, and the other n−h papers has no more than H citation S each. "
For example, given citations = [3, 0, 6, 1, 5]
, which means the researcher have papers in total and each of 5
them had received 3, 0, 6, 1, 5
Citatio NS respectively. Since the researcher have papers with at least citations each and the remaining both with 3
3
no more than 3
CIT Ations each, he h-index is 3
.
Note:if there was several possible values h
for, the maximum one is taken as the h-index.
Feel this problem more like moving return, did not write out, saw others ' realization, the code is as follows:
1 classSolution {2 Public:3 intHindex (vector<int>&citations) {4 intn =citations.size ();5vector<int>index (n +1,0);//notice this is n+1 .6 for(inti =0; I < n; ++i) {7 if(citations[i]>=N)8index[n]++;9 ElseTenindex[citations[i]]++; One } A if(Index[n] >= N)returnN; - for(inti = citations.size ()-1; I >=0; --i) { -index[i]+=index[i+1]; the if(Index[i] >=i) - returni; - } - return 0; + } -};
Leetcode oj:h-index (H index)