短路求值新用处
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; } };
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步