leetcode H-Index (I、II)
来源:互联网 发布:赛尔网络个人业务天津 编辑:程序博客网 时间:2024/06/03 21:56
class Solution {// I1 public: int hIndex(vector<int>& citations) { sort(citations.begin(),citations.end()); int ret = 0; for (int i = 0 ; i < citations.size(); ++i){ int tmp = min (citations[i], (int)citations.size() - i); if (ret <= tmp) ret = tmp; else break; } return ret; }};
class Solution { // I2public: int hIndex(vector<int>& citations) { vector<int> count(citations.size() + 1, 0); for (int i = 0; i < citations.size(); ++i){ if ( citations[i] < citations.size()) count[citations[i]] ++; // 统计数字出现的次数 else count[citations.size()]++; } int ret = 0, cnt = 0; for (int i = 0; i < count.size(); ++i){ if (count[i]){ int tmp = min (i, (int)citations.size() - cnt); if (ret <= tmp){ ret = tmp; cnt += count[i]; } else break; } } return ret; }};
class Solution { // IIpublic: int hIndex(vector<int>& citations) { if (citations.empty()) return 0; int low = 0, high = citations.size() - 1, ret = 0; while (low <= high){ int mid = (low + high) / 2; if (citations[mid] >= citations.size() - mid) high = mid - 1; else low = mid + 1; } return min ((int)citations.size() - low, citations[low]); }};
0 0
- LeetCode-H-Index I & II
- leetcode H-Index (I、II)
- [leetcode 274 275]H-Index I II
- [leetcode] 274 275 H-Index I && II
- 【LeetCode从零单刷】H-index I & II
- Leetcode: H-Index II
- Leetcode: H-Index II
- [LeetCode]H-Index II
- H-Index II -- leetcode
- LeetCode H-Index II
- leetcode H-Index II
- [Leetcode]H-Index II
- [LeetCode] H-Index II
- LeetCode -- H-Index II
- [LeetCode]H-Index II
- LeetCode:H-Index II
- 【Leetcode】H-Index II
- Leetcode H-Index II
- java开发编译器:中间语言格式
- bjfu1070 一道简单的数学题
- Spring—Quartz定时调度CronTrigger时间配置格式说明与实例
- 算法讲解:二分图匹配
- 基础第二天
- leetcode H-Index (I、II)
- Android 城市选择
- Android中的计量单位
- ARM平台上蓝牙协议栈Bluez的移植使用和配置
- MySQL更新多行信息
- 桶排序
- SQL Server 存储过程
- float浮动布局,auto冻结布局,position:absolute绝对布局
- java.io.EOFException错误