https://leetcode.com/problems/h-index/

https://leetcode.com/mockinterview/session/result/xjcpjlh/

看了hint,不然的话,可能用的是排序的方法,O(NlgN),现在的方法用了extra space,但是时间复杂度是O(N).

package com.company;

import java.util.*;

// https://discuss.leetcode.com/topic/32272/share-my-greedy-solution/2

class Solution {
public int hIndex(int[] citations) {
int[] rec = new int[citations.length]; for (int i=0; i<citations.length; i++) {
if (citations[i] >= 1 && citations[i] <= citations.length) {
rec[citations[i]-1]++;
}
else if (citations[i] > citations.length) {
rec[citations.length-1]++;
}
} int count = 0;
for (int i=citations.length; i>0; i--) {
count += rec[i-1];
if (count >= i) {
return i;
}
}
return 0;
}
} public class Main { public static void main(String[] args) throws InterruptedException { System.out.println("Hello!");
Solution solution = new Solution(); // Your Codec object will be instantiated and called as such:
int[] citations = {3, 0, 6, 1, 5}; int ret = solution.hIndex(citations);
System.out.printf("ret:%d\n", ret); System.out.println(); } }

h-index的更多相关文章

  1. HDU-6278-Jsut$h$-index(主席树)

    链接: https://vjudge.net/problem/HDU-6278 题意: The h-index of an author is the largest h where he has a ...

  2. jQuery—一些常见方法(1)【filter(),not(),has(),next(),prev(),find(),eq(),index(),attr(),】

    1.filter()和not()方法 filter()和not()是一对反方法,filter()是过滤. filter()方法是针对元素自身.(跟has()方法有区别) <script type ...

  3. FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  4. [LeetCode] 274. H-Index H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  5. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

  6. jquery基本操作笔记

    来源于:http://www.cnblogs.com/webcome/p/5484005.html jq和js 可以共存,不能混用: 1 2 3 4 5 6 $('.box').css('backgr ...

  7. layer——源码学习

    一.根据源码的学习 发现创建弹窗:使用了一些div来组成 zindex 和 index 是自动生成. zindex 表示生成的层次关系 index 用来表示各个层的id 默认class名 h = [& ...

  8. 多功能弹窗控件layer

    开发网站的时候,如何合理运用好各种插件对开发的帮助是很大的. 免去了我们调试各种交互效果, 比如常用的弹窗.气泡.提示.加载.焦点.标签.导航.折叠等等 这里会推荐几个常用的js插件,丰富多样简单易移 ...

  9. 面试题:给定数组a,找到最大的j-i, 使a[j]>a[i]

    第一种方法: 用两重循环对每对点都试一下,然后取最大值即可,时间复杂度为O(n2) #include <iostream> #include <algorithm> using ...

  10. web图片识别

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

随机推荐

  1. Auto Layout - 使用总结

    1.要开始使用AutoLayout,请先设置要约束的view的translatesAutoresizingMaskIntoConstraints属性为NO.在xib或者sb中勾选Use Auto La ...

  2. UML用例图(转载)

    概述: 为了模拟系统最重要的方面是捕捉到的动态行为.为了阐明位详细信息,动态的行为意味着它运行时/操作系统的行为. 因此,只有静态的行为是不够的模拟系统,而动态的行为,更重要的是比静态行为.在UML模 ...

  3. 【转】CSS实现div的高度填满剩余空间

    转自:http://www.cnblogs.com/zhujl/archive/2012/03/20/2408976.html 高度自适应问题,我很抵触用js去解决,因为不好维护,也不够自然,但是纯用 ...

  4. 小奇模拟赛9.13 by hzwer

    2015年9月13日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿(explo) [题目背景] 小奇要开采一些矿物,它驾驶着一台带有钻头(初始能力值w)的飞船,按既定路线依次飞 ...

  5. Project Euler 109 :Darts 飞镖

    Darts In the game of darts a player throws three darts at a target board which is split into twenty ...

  6. Redis 集群实现

    Nosql,作为程序员在当下不了解点儿,还真不行,出去聊起来别人就会说你土.那么就聊聊其中一个比较火的redis.redis单机版没得说,但是一直没有集群版,有也是山寨的.前段时间对redis的实现进 ...

  7. java应用程序利用Exe4j打包exe文件

    1.      使用简介: 把java应用程序打成exe文件我们可以借助第三方软件exe4j来完成.Exe4j大家可以在网上下载,下载地址是: http://www.ej-technologies.c ...

  8. java开发--JavaScript

    http://www.cnblogs.com/hongten/archive/2011/03/21/1990121.html JavaScript表单验证电话号码,判断一个输入量是否为电话号码,通过正 ...

  9. SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-004JPA例子的代码

    一.结构 二.Repository层 1. package spittr.db; import java.util.List; import spittr.domain.Spitter; /** * ...

  10. VCL设计方法概论(自己总结了9条),以及10个值得研究的控件 good

    VCL设计方法概论 1. 把Delphi对象改造成一个Windows窗口,主要是要设置Handle和回调函数.在创建一个Windows窗口后,将其句柄赋值给Delphi对象的属性,这个并不难,相当于从 ...