题目

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测试程序源码

LeetCode(275)H-Index II的更多相关文章

  1. 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 ...

  2. LeetCode(90):子集 II

    Medium! 题目描述: 给定一个可能包含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: [1,2,2] 输出: [ [2], [1 ...

  3. LeetCode(219) Contains Duplicate II

    题目 Given an array of integers and an integer k, find out whether there are two distinct indices i an ...

  4. LeetCode(137) Single Number II

    题目 Given an array of integers, every element appears three times except for one. Find that single on ...

  5. LeetCode (45) Jump Game II

    题目 Given an array of non-negative integers, you are initially positioned at the first index of the a ...

  6. LeetCode(59)SPiral Matrix II

    题目 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. F ...

  7. LeetCode(47):全排列 II

    Medium! 题目描述: 给定一个可包含重复数字的序列,返回所有不重复的全排列. 示例: 输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ] 解题思路: 这道 ...

  8. LeetCode(40) Combination Sum II

    题目 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations ...

  9. LeetCode(63)Unique Paths II

    题目 Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. Ho ...

随机推荐

  1. python 1 学习廖雪峰博客

    输出 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print('hello, world') p ...

  2. 开机报错 the connected AC adapter has a lower wattage than the recommended model which was shipped with the system。

    机型:联想Thinkpad T410 报错场景:在电脑插上电源充电情况下开机,会自动进入bios setup utility提示你需要重新设置日期时间.date/time 报错提示:The conne ...

  3. css3Transitions 实现的鼠标经过图标位移、旋转、翻转、发光、淡入淡出等多种特效

    HTML如下:   1 <div class="container"> 3 <!--特效1 --> <section id="set-1&q ...

  4. ABAP自定义功能函数

    1.实现计算器中阶乘函数 FUNCTION zfun_mm_001. *"---------------------------------------------------------- ...

  5. Android里的网格空隙

    在很多移动端或者web端开发中我们会遇到很多网格布局,如果我们使用线性布局来实现一些简单的网格布局就需要使用padding/margin等属性来使其对齐,代码如下: <LinearLayout ...

  6. eclipse的垂直选择功能

    快捷键:Alt+Shift+A切换. 光标会变成十字,就可以垂直选择了.

  7. C++拾遗(六)——复制控制

    年前忙了几天,到现在才算是有空休息下来.先祝大家新年快乐,心想事成:)我也会发笑脸o.o 这篇博文主要介绍定义一个类型的对象时的复制控制方式,这部分内容之前有一定的了解但又浅尝辄止,始终感觉没能找到要 ...

  8. 将一个字符与对应Ascii码互转

    package nicetime.com.practies; /** * Java中将一个字符与对应Ascii码互转 1 byte = 8bit 可以表示 0-127 */public class G ...

  9. javaSe数据类型

    在学完了java程序的结构以及注释后呢按照一般的教程我们应该学点什么呢?   没错就是变量和数据类型[其实我的内心是拒绝的,又是无聊的一大堆,不仅无聊,还得掌握] 好了首先介绍什么是变量: 变量:变量 ...

  10. servlet的重定向和作用域

    <?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://w ...