leetcode: H-Index
来源:互联网 发布:西方教父教母地位知乎 编辑:程序博客网 时间:2024/06/05 14:33
计算h值,比较容易想到的方法是将输入数组排序,从大到小与坐标比较...代价是O(nlgn)的....
还可以牺牲O(n)的空间来使时间复杂度降低到O(n)...具体做法就是维护一个n+1的数组tmp记录citations中各个数出现的个数(当citations[i]>=len时,tmp[len]++)
之后再从大到小遍历tmp,累加tmp[i]作为count,当第一个出现count>=坐标i的事后即可返回...
public class Solution { public int hIndex(int[] citations) { int len = citations.length; if( len==0 ) { return 0; } int[] tmp = new int[len+1]; for( int i=0;i<len;i++ ) { if(citations[i]>=len) { tmp[len]++; } else { tmp[citations[i]]++; } } int count=0; for( int i=len;i>=0;i-- ) { count+=tmp[i]; if( count>=i) { return i; } } return 0; }}
0 0
- Leetcode 274 : H-index
- leetcode H-Index
- [leetcode][sort] H-Index
- 【leetCode】H-Index
- Leetcode: H-Index
- Leetcode: H-Index II
- leetcode 274: H-Index
- [leetcode] 274.H-Index
- leetcode 之 H-index
- LeetCode: H-Index
- leetcode H-index 2
- Leetcode: H-Index
- Leetcode: H-Index II
- leetcode: H-Index
- [LeetCode 274] H-index
- [LeetCode]H-Index
- [LeetCode]H-Index II
- H-Index -- leetcode
- iOS如何获取iOS app的资源包
- Android Handler机制
- android dp
- java学习之System类
- Swift中的集合类数据结构
- leetcode: H-Index
- max-min fairness 最大最小公平算法
- C# winform: 初始化ListView
- html jquery 开发小技巧
- Differences between ArrayList and Vector
- iptables-rules
- Ubuntu安装软件时出现错误:Reading package lists... Error!
- Linux下解决命令未找到的问题
- sizeof与strlen