h-index

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();

    }

}
时间: 2024-08-05 17:50:34

h-index的相关文章

H.264解码过程剖析-4

x264开源工程实现H.264的视频编码,但没有提供对应的解码器.ffmpeg开源多媒体编解码集合汇集了市面上几乎所有媒体格式的编解码的源代码.其中的H264.c就是一个能正常解码x264编码码流的独立的源文件,其使用步骤也与上述的编码或解码CODEC应用案例基本相同.这一节通过自顶向下的方式,讲述H264.c如何实现H.264视频解码过程. H264.c源文件有几千行,代码量庞大,很不便于浏览.分析和移植.同时该文件还依赖其他源文件,组织结构较复杂,实现平台由于不是基于Windows的VC++

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

本文分析FFmpeg的H.264解码器的熵解码(Entropy Decoding)部分的源代码.FFmpeg的H.264解码器调用decode_slice()函数完成了解码工作.这些解码工作可以大体上分为3个步骤:熵解码,宏块解码以及环路滤波.本文分析这3个步骤中的第1个步骤. 函数调用关系图 熵解码(Entropy Decoding)部分的源代码在整个H.264解码器中的位置如下图所示. 单击查看更清晰的图片 熵解码(Entropy Decoding)部分的源代码的调用关系如下图所示. 单击查

[LeetCode] 274. H-Index H指数

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have a

uva10282-字典

此题为小白书暴力求解法哈希表的训练参考 题目链接 http://acm.hust.edu.cn/vjudge/problem/24031 最近为了快速入门...所以挑了些简单的题目先做... 解题思路 最多会录入100000个单词对.可以设计一个简单的哈希函数,比如下标*单词这样的, 当然这样会造成较多冲突,如果是极限数据的话装填因子a达到了100... 如果用拉链法解决冲突的话,平均查找长度其查找成功大概是50左右,速度上还是可以凑合的. 填装因子a = 填入表中记录的个数 / 散列表的长度

leetcode -eleven:Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a containe

回文数 第N个回文数

判断回文数还是不难,如果能转为字符串就更简单了. 如果是求第N个回文数呢. 12321是一个回文数,这里先考虑一半的情况. 回文数的个数其实是有规律的.如: 1位回文数: 9个 2位回文数: 9个 3位回文数: 90个 4位回文数: 90个 5位回文数: 900个 6位回文数: 900个 … 我们看到9.90.900,是不是很有规律,那是什么原因?很简单,我们把回文数拆开两半 [123321]来看.两半的变化一样的,那我们只算其中一半就行了.首位不能是0,所以左半最小为 100,最大为999,共

(转)让所有浏览器支持HTML5 video视频标签

转自http://www.zhangxinxu.com/wordpress/?p=661 一.前面的唠叨 我记得就是前几个月吧,有条消息说YouTube支持了HTML5视频嵌入标签video,好吧,我听说而已,因为我不是个擅长FQ的人,到底如何我也不得而知. 与主题不相关的HTML5方面的东西我就不多说了,对于video标签,获取大家都听说了,这个标签的功能如同现在HTML语言中的img标签,就现在,比如要链接并显示一张图片,可以这样子: <img data-src="http://ima

JQuery基础二

$()下的常用方法 has() not() filter() next() prev() find() eq() index() attr() Filter:过滤 not:filter的反义词 $("div").filter(".box").css("background","red"); $("div").not(".box").css("background",&

[BZOJ 1014] [JSOI2008] 火星人prefix 【Splay + Hash】

题目链接:BZOJ - 1014 题目分析 求两个串的 LCP ,一种常见的方法就是 二分+Hash,对于一个二分的长度 l,如果两个串的长度为 l 的前缀的Hash相等,就认为他们相等. 这里有修改字符和插入字符的操作,所以用 Splay 来维护串的 Hash 值. 一个节点的值就是它的子树表示的字串的 Hash 值. 使用 unsigned long long 然后自然溢出就不需要 mod 了,速度会快很多. 代码 #include <iostream> #include <cstd

hdu 1535 Invitation Cards 大年初一首A 一次正向SPFA+一次逆向SPFA

Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2311    Accepted Submission(s): 1125 Problem Description In the age of television, not many people attend theater performances.