LeetCode(275)H-Index II
2024-09-04 14:42:12
题目
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
分析
同LeetCode(274)H-Index第二个版本,给定引用数量序列为递增的;这就省略了我们的第一个排序步骤;
O(n)的时间复杂度,遍历一次即可。
AC代码
class Solution {
public:
int hIndex(vector<int>& citations) {
if (citations.empty())
return 0;
int len = citations.size(), maxH = 0;
for (int i = len - 1; i >= 0; --i)
{
int h = len - i;
if (citations[i] >= h && h > maxH)
{
maxH = h;
}
else{
break;
}
}//for
return maxH;
}
};
最新文章
- JavaScript replace() 方法
- go语言常用函数:copy
- C++ 遇到的问题小结
- 防火墙设置:虚拟机ping不通主机,但是主机可以ping通虚拟机(转载)
- Java Se 基础系列(笔记) -- BasicDataType
- QQ互联申请及配置
- python之celery的使用(一)
- 关于根据模板生成pdf文档,差入图片和加密
- 跟着 underscore 学节流
- finance1:专业词汇
- [转]zookeeper-端口说明
- JavaScript:jklyDB
- IOS使用AVAudioPlayer播放mp3歌曲文件并监听来电打断
- 如何在IntelliJ IDEA中快速配置Tomcat
- zabbix第一篇:zabbix安装及使用
- 如何用Latex合并多个pdf文件?
- FastReport.Net使用:[6]HTML标签使用
- 在VritualBox中安装CentOS7
- 其实参与QtCreator开发也很容易
- Entity Framework Tutorial Basics(35):Local Data
热门文章
- EOJ Problem #3261 分词 trie + dp + 小剪枝
- Redis的数据类型(Strings、 hashes)
- C#数据类型 值传递和引用传递
- readonly与const的区别
- 关于Linux系统启动时出现UVD not responding, Trying to reset the vcpu问题的解决
- 环境变量&mdash;《linux命令行与shell脚本编程大全》
- Mac下安装ElasticSearch及其插件
- android 跨进程通讯 AIDL
- 51nod 1693 水群
- 感觉单链表是实现BCL ICollection 的最佳方式,所有操作都能以最小的时间复杂度完成