LeetCode(275)H-Index II
题目
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;
}
};
LeetCode(275)H-Index II的更多相关文章
- LeetCode(113) Path Sum II
题目 Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given ...
- LeetCode(90):子集 II
Medium! 题目描述: 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ [2], [1 ...
- LeetCode(219) Contains Duplicate II
题目 Given an array of integers and an integer k, find out whether there are two distinct indices i an ...
- LeetCode(137) Single Number II
题目 Given an array of integers, every element appears three times except for one. Find that single on ...
- LeetCode (45) Jump Game II
题目 Given an array of non-negative integers, you are initially positioned at the first index of the a ...
- LeetCode(59)SPiral Matrix II
题目 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. F ...
- LeetCode(47):全排列 II
Medium! 题目描述: 给定一个可包含重复数字的序列,返回所有不重复的全排列. 示例: 输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ] 解题思路: 这道 ...
- LeetCode(40) Combination Sum II
题目 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations ...
- LeetCode(63)Unique Paths II
题目 Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. Ho ...
随机推荐
- Jenkins+Gitlab+Ansible自动化部署(五)
Freestyle Job实现静态网站部署交付(接Jenkins+Gitlab+Ansible自动化部署(四)https://www.cnblogs.com/zd520pyx1314/p/102445 ...
- hadoop集群启动时DataNode节点启动失败
错误日志如下: ************************************************************/ 2018-03-07 18:57:35,121 INFO o ...
- 在MVC中使用dotless后台动态解析LESSCSS的学习笔记
通过学习LessCSS,我们知道,Less是需要通过编译才能生成 .css 文件,主要使用三种方式进行编译: 1)使用第三方编译工具,在项目发布前编译好放在项目中. 2)在浏览器端解析执行,需要引用 ...
- Dev控件工具箱安装
安装目录\Components\Tools,打开命令行 安装DEV工具 $ ToolboxCreator.exe /ini:toolboxcreator.ini 移除DEV工具 $ ToolboxCr ...
- Android 网络提交数据(使用Asynchronous Http Client)
项目主页及简单使用方法http://loopj.com/android-async-http/ 页面布局就不复制了,把主要的Activity记录下来,供自己以后使用: package com.exam ...
- I/O————流
流的关系图 缓冲流分为字节和字符缓冲流(图中是经常用的搭配,PrintWrite与BufferedWrite都继承java.io.Write) 字节缓冲流为: BufferedInputStream— ...
- Class 学习 (Es6阮一峰)
es5 构造函数 实例: function Point(x, y) { this.x = x; this.y = y; } Point.prototype.toString = function () ...
- (2017.10.10) 我对 JavaScript 历史的认识
关于 JavaScript 的历史和来由相信学过 JavaScript 的小伙伴都能说出一二.我看过一些入门书籍第一章或者前言部分都有介绍,但是一直没捋清这段历史.今天通过两个问题,来加深我对 Jav ...
- UIButton 图片文字位置
在实际开发过程中经常在按钮上添加文字和图片,位置和图片的位置根据需求放置也是不一样的.下面实现了各种显示方式,如下图: UIButton+LSAdditions.h // // UIButton+LS ...
- Core Data stack
https://developer.apple.com/library/content/documentation/DataManagement/Devpedia-CoreData/coreDataS ...