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 ...
随机推荐
- spring基础概念AOP与动态代理理解
一.代理模式 代理模式的英文叫做Proxy或Surrogate,中文都可译为”代理“,所谓代理,就是一个人或者一个机构代表另一个人或者另一个机构采取行动.在一些情况下,一个客户不想或者不能够直接引用一 ...
- (转) RHEL7 忘记密码修改root密码
博客链接:http://blog.csdn.net/derkampf/article/details/54346516 RHEL7进入单用户方式和重置密码方式发生了较大变化,GRUB由b引导变成了ct ...
- 【0 基础学Dojo】第【1】篇 HelloWord
打开dojo 官网首页 http://dojotoolkit.org/,我们看到 点击get dojo 你将得到下载Dojo 的不同方式 2,点击下面方式下载, 解压后 新建myTest.html, ...
- 选择控件js插件和使用方法
记录一下 选择控件js插件 /* * 滚动控件,包含地址选择.时间选择.自定义单选 */ //js_inputbox input 输入框 //js_pickviewselect 下拉单项选择 //js ...
- DHTMLX 使用汇总
1.dhtmlxGrid 底部总出现滚动条 ------------------------------------------ 发现使用DHTMLXGRID时 GRID 底边总有 滚动条 测试 ...
- springmvc学习经验
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring ...
- C语言的time函数和localtime函数
1.获取当前时间,并获取当前时间(即系统时间)距离1970年1月1日的时间间隔,以秒为单位. 2.获取指定时间距离1970年1月1日的时间间隔,以秒为单位.
- python+selenium之断言Assertion
一.断言方法 断言是对自动化测试异常情况的判断. # -*- coding: utf-8 -*- from selenium import webdriver import unittest impo ...
- jsp跳转标签<jsp:forward>
forward.jsp <%@ page language="java" contentType="text/html; charset=utf-8" p ...
- wall命令
wall——发送广播信息 write all /usr/bin/wall 示例1: # wall 输入命令之后回车便可以广播消息,如输入Hello everybody online后Ctrl+D结束并 ...