[LeetCode]275. H-Index II
来源:互联网 发布:sql for in 循环语句 编辑:程序博客网 时间:2024/06/08 07:05
Follow up for H-Index: What if the citations
array is sorted in ascending order? Could you optimize your algorithm?
思路:这个就是给你从小到大排序过的数组了,可以直接用上一个算法解决了。。。
让h先等于n(能取到的最大数),然后用nums[n-h]与h相比较,因为大于nums[n-h]的数量正好为h个,如果nums[n-h]>=h,则说明存在有h个大于等于h的数,如果不是则把h减一,循环继续找
AC之后看了下统计结果。。。发现很差很差。。。还有更好的算法
public class Solution { public int hIndex(int[] citations) { int n=citations.length; int h=n; while(h!=0){ if(citations[n-h]>=h){ return h; }else{ h--; } } return 0; }}
0 0
- [leetcode] 275.H-Index II
- 275. H-Index II LeetCode
- leetcode 275. H-Index II
- LeetCode *** 275. H-Index II
- leetcode.275. H-Index II
- LeetCode - 275. H-Index II
- [leetcode] 275. H-Index II
- LeetCode 275. H-Index II
- 【LeetCode】 275. H-Index II
- Leetcode 275. H-Index II
- [LeetCode]275. H-Index II
- leetcode 275. H-Index II
- leetcode 275. H-Index II
- Leetcode: H-Index II
- Leetcode: H-Index II
- [LeetCode]H-Index II
- H-Index II -- leetcode
- LeetCode H-Index II
- 将输入流InputStream转换为String
- Java学习笔记
- java树 JTree实例(可动态添加节点)
- 数独破解(回溯,暴力dfs+剪枝)
- Logistic回归模型(C++代码实现)
- [LeetCode]275. H-Index II
- TopCoder-AB
- 带你玩转安卓的开源框架
- codeforces 798B
- 升级 SpringMVC 4.2.5 com/fasterxml/jackson/core/JsonProcessingException
- CentOS下go 语言开发环境源码安装
- openssl-1.0.2编译和安装
- ZOJ 1489
- POJ 1990 树状数组