首页 > 其他 > 详细

短路求值新用处

时间:2015-09-06 15:57:05      阅读:313      评论:0      收藏:0      [点我收藏+]

https://leetcode.com/problems/h-index/

class Solution {
public:
    int hIndex(vector<int>& citations) {
        priority_queue<int> pq;
        for(int i=0;i<citations.size();i++){
            pq.push(citations[i]);
        }
        int pages=0;
        while(!pq.empty()){
            int cur = pq.top();
            pq.pop();
            pages++;
            // 在取下一个值时候先判定是否为空
            if(cur >= pages && (pq.empty() || pages >= pq.top())) return pages;
        }
        
        return 0;
    }
};

 

短路求值新用处

原文:http://www.cnblogs.com/daijkstra/p/4785604.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!