H-Index

题目链接:https://leetcode.com/problems/h-index/

题目大意:其实就是求最大的h,能够保证研究员的h篇paper,每篇至少都有h篇引用,要求最大的h

解析:

比较容易想到的就是先对paper按照引用数进行递减排序

首先设定h = 0, 如果当前paper的引用数>= h+1,则说明可以增加h的值,因为多了一篇paper满足h+1的引用,自然h也得加1

实现代码很简单,如下:

int cmp(int a, int b)
{
    return a > b;
}

class Solution {
public:
    int hIndex(vector<int>& citations) {
        sort(citations.begin(), citations.end(), cmp);
        
        
        int h = 0;
        for(int i=0; i<citations.size(); ++i)
        {
            if(citations[i] >= h+1)
            {
                ++h;
            }
        }
        
        return h;
    }
};

 

posted @ 2016-06-20 21:29  Shirley_ICT  阅读(284)  评论(0编辑  收藏  举报