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. jquery的ajax同步和异步的理解及示例

    之前一直在写JQUERY代码的时候遇到AJAX加载数据都需要考虑代码运行顺序问题.最近的项目用了到AJAX同步.这个同步的意思是当JS代码加载到当前AJAX的时候会把页面里所有的代码停止加载,页面出去 ...

  2. 在JavaScript中实现yield,实用简洁实现方式。

    原题还是老赵的: http://blog.zhaojie.me/2010/06/code-for-fun-iterator-generator-yield-in-javascript.html 原以为 ...

  3. SOA之(4)——服务实现的途径

    服务实现的途径(Service Implementation Mediums) 将SOA看成是一个架构模型非常重要,它独立于任何技术平台.对于企业来说,可以根据它当前自身的技术优势来实现SOA,从而达 ...

  4. -高级Javascript编程学习笔记----Javascript编程及架构设计最应该注意的基本点

    最小全局变量 JavaScript通过函数管理作用域.在函数内部生命的变量只在这个函数内部,别的地方不可用.全局变量是指在函数外或是未声明直接简单使用的.每个Javascipt环境有一个全局对象,当你 ...

  5. ZOJ3554 A Miser Boss(dp)

    给你n个工件,然后有A,B,C三个工厂,然后它们加工第i个工件所需要的时间分别为a[i],b[i],c[i],然后现在要你利用三间工厂加工所有的零件,要求是任何时间工厂都不能停工,而且一定要三间同时做 ...

  6. Simulate a seven-sided die using only five-sided

    问题描述: 如题 转述一下问题,就是说你现在有一个正五面体骰子,然后你怎么用这个正五面体骰子去模拟一个正七面体骰子. 这个问题我接触到几种方法,下面一一阐述. 方法一: rand7()=( rand5 ...

  7. C# 中Newtonsoft.Json的安装和使用

    官网参考:http://json.codeplex.com/ 在程序包管理控制台,键入NuGet命令  install-package Newtonsoft.Json  安装Newtonsoft.Js ...

  8. hdu 4768 Flyer 二分

    思路:由于最多只有一个是奇数,所以二分枚举这个点,每次判断这个点的左边区间段所有点的和作为 二分的依据. 代码如下: #include<iostream> #include<cstd ...

  9. C#中对象的输出

    假设有个Costmer类如下: class Costmer { public string Id { get; set; } public string City { get; set; } publ ...

  10. Project Euler 110:Diophantine reciprocals II 丢番图倒数II

    Diophantine reciprocals II In the following equation x, y, and n are positive integers. For n = 4 th ...