[Leetcode] Binary search--275 H-Index
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
Solution:
here we use binary search
inspired from sorting method c[i] < i+1;
when citations c is in ascending order, the idea is find the minimum index c[i] >= len(c) -i
l = 0
h = len(citations)-1
while (l <= h):
mid = (l+h)/2
if citations[mid] == len(citations)-mid:
return len(citations)-mid
elif citations[mid] < len(citations)-mid:
l = mid+1
else:
h = mid-1 return len(citations)-l
[Leetcode] Binary search--275 H-Index的更多相关文章
- [LeetCode] Binary Search 二分搜索法
Given a sorted (in ascending order) integer array nums of n elements and a target value, write a fun ...
- LeetCode Binary Search All In One
LeetCode Binary Search All In One Binary Search 二分查找算法 https://leetcode-cn.com/problems/binary-searc ...
- LeetCode & Binary Search 解题模版
LeetCode & Binary Search 解题模版 In computer science, binary search, also known as half-interval se ...
- [Leetcode] Binary search -- 475. Heaters
Winter is coming! Your first job during the contest is to design a standard heater with fixed warm r ...
- [LeetCode] Binary Search Tree Iterator 二叉搜索树迭代器
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...
- LeetCode Binary Search Tree Iterator
原题链接在这里:https://leetcode.com/problems/binary-search-tree-iterator/ Implement an iterator over a bina ...
- LeetCode: Binary Search Tree Iterator 解题报告
Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). Your iterator wil ...
- 153. Find Minimum in Rotated Sorted Array(leetcode, binary search)
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/ leetcode 的题目,binary ...
- [Leetcode] Binary search, DP--300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- LeetCode——Binary Search Tree Iterator
Description: Implement an iterator over a binary search tree (BST). Your iterator will be initialize ...
随机推荐
- 安卓Native和H5页面进行交互
安卓Native和H5页面进行交互 1.H5页面调用安卓Native界面 1)通过给webView添加JsInterface,安卓提供接口,让H5来进行调用 a)安卓写一个类,里面的方法需要用通 ...
- Hibernate学习--hibernate延迟加载原理(动态代理)
在正式说hibernate延迟加载时,先说说一个比较奇怪的现象吧:hibernate中,在many-to-one时,如果我们设置了延迟加载,会发现我们在eclipse的调试框中查看one对应对象时,它 ...
- DFB系列 之 Bilp叠加
1. 函数原型解析 函数声明: DFBResult Blit ( IDirectFBSurface * thiz, IDirectFBSurface * source ...
- ASP.Net零碎
ASP.Net零碎 ServerPush 什么是ServerPush,服务器向客户端浏览器“推送”,其实就是“长连接”. 只有浏览器请求服务器端,服务器端才有给浏览器响应数据,不会主动向浏览器推送数据 ...
- 运行出错之未能加载文件或程序集“Microsoft.ReportViewer.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”或它的某一个依赖项。系统找不到指定的文件。文件名:“Microsoft.ReportViewer.Common, Version=11.0.0.0,
这个问题是因为在项目中缺少Microsoft.ReportViewer.Common程序集. 方法一:缺少哪些文件或程序集,到程序开发计算机下找到对应的烤到客户端的程序启动目录下即可(项目烤到Bin\ ...
- 分布式锁与实现(二)——基于ZooKeeper实现
引言 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提 ...
- Spring框架 jar包下载
Spring框架下载 打开网址https://repo.spring.io 点击左侧边栏第二个按钮 点击 在输入框输入spring-framework点击Search 找到你需要的版本下载就好 教程到 ...
- 关于使用命令添加jar进自己的pom文件中-maven项目添加jar包
现在几乎开发项目都是使用的maven项目,但是有的时候可以使用比较偏门或者新的jar可能在网上搜不到在pom文件里的配置应该如何写,因此写下这篇博客. 比如我现在想加入的AAA.jar这个包 打开cm ...
- poj 1088 动态规划
#include <iostream> #include <string.h> using namespace std; ][];//存储当前位置能得到的最优解 ][];//存 ...
- ios模拟器bug
Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Libra ...