题目

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;
}
};

GitHub测试程序源码

最新文章

  1. JavaScript replace() 方法
  2. go语言常用函数:copy
  3. C++ 遇到的问题小结
  4. 防火墙设置:虚拟机ping不通主机,但是主机可以ping通虚拟机(转载)
  5. Java Se 基础系列(笔记) -- BasicDataType
  6. QQ互联申请及配置
  7. python之celery的使用(一)
  8. 关于根据模板生成pdf文档,差入图片和加密
  9. 跟着 underscore 学节流
  10. finance1:专业词汇
  11. [转]zookeeper-端口说明
  12. JavaScript:jklyDB
  13. IOS使用AVAudioPlayer播放mp3歌曲文件并监听来电打断
  14. 如何在IntelliJ IDEA中快速配置Tomcat
  15. zabbix第一篇:zabbix安装及使用
  16. 如何用Latex合并多个pdf文件?
  17. FastReport.Net使用:[6]HTML标签使用
  18. 在VritualBox中安装CentOS7
  19. 其实参与QtCreator开发也很容易
  20. Entity Framework Tutorial Basics(35):Local Data

热门文章

  1. EOJ Problem #3261 分词 trie + dp + 小剪枝
  2. Redis的数据类型(Strings、 hashes)
  3. C#数据类型 值传递和引用传递
  4. readonly与const的区别
  5. 关于Linux系统启动时出现UVD not responding, Trying to reset the vcpu问题的解决
  6. 环境变量&mdash;《linux命令行与shell脚本编程大全》
  7. Mac下安装ElasticSearch及其插件
  8. android 跨进程通讯 AIDL
  9. 51nod 1693 水群
  10. 感觉单链表是实现BCL ICollection 的最佳方式,所有操作都能以最小的时间复杂度完成