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(); } }
h-index的更多相关文章
- 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 ...
- jQuery—一些常见方法(1)【filter(),not(),has(),next(),prev(),find(),eq(),index(),attr(),】
1.filter()和not()方法 filter()和not()是一对反方法,filter()是过滤. filter()方法是针对元素自身.(跟has()方法有区别) <script type ...
- FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分
===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...
- [LeetCode] 274. H-Index H指数
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- 【机器学习Machine Learning】资料大全
昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...
- jquery基本操作笔记
来源于:http://www.cnblogs.com/webcome/p/5484005.html jq和js 可以共存,不能混用: 1 2 3 4 5 6 $('.box').css('backgr ...
- layer——源码学习
一.根据源码的学习 发现创建弹窗:使用了一些div来组成 zindex 和 index 是自动生成. zindex 表示生成的层次关系 index 用来表示各个层的id 默认class名 h = [& ...
- 多功能弹窗控件layer
开发网站的时候,如何合理运用好各种插件对开发的帮助是很大的. 免去了我们调试各种交互效果, 比如常用的弹窗.气泡.提示.加载.焦点.标签.导航.折叠等等 这里会推荐几个常用的js插件,丰富多样简单易移 ...
- 面试题:给定数组a,找到最大的j-i, 使a[j]>a[i]
第一种方法: 用两重循环对每对点都试一下,然后取最大值即可,时间复杂度为O(n2) #include <iostream> #include <algorithm> using ...
- web图片识别
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
随机推荐
- sqlserver 查询库中有多少张表
表数目:select count(1) from sysobjects where xtype='U' 视图数::select count(1) from sysobjects where xtype ...
- 【中国互联网不眠夜】Struts2漏洞百出,OneRASP鼎力相助
Struts2是一款优秀的网站框架,在互联网上有十分广泛的应用,近期apache官方发布了高危漏洞通告Apache Struts 任意代码执行漏洞(CVE-2016-3081,S2-032),该漏洞风 ...
- Leetcode: strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- Linux网络编程2——系统函数
socket信息数据结构 #include <netinet/in.h> struct sockaddr { unsigned short sa_family; /*地址族*/ ]; /* ...
- MongoDB的安装,配置与开机自启动
关于简介不多说百度去吧少年.. MongoDB详细安装: 1.进入官网,点击DOWNLOAD MONGODB,下载所需要的版本.. 我这里把下载的文件放在d\MongoDB文件夹下,点击下载的官方镜像 ...
- powermockito “mock public 方法内部 Private方法的问题”
我需要测试的方法是 public 方法: public ResponseResult subscribe(SysSubscription sysSubscription) throws JsonGen ...
- 用C语言写个程序推算出是星期几?(用泰勒公式实现)
在日常生活中,我们常常遇到要知道某一天是星期几的问题.有时候,我们还想知道历史上某一天是星期几.比如: “你出生的那一天是星期几啊?” “明年五一是不是星期天?我去找你玩?” 通常,解决这个问题的最简 ...
- React架构、设计思想
一.
- keil MDK中如何生成*.bin格式的文件
在Realview MDK的集成开发环境中,默认情况下可以生成*.axf格式的调试文件和*.hex格式的可执行文件.虽然这两个格式的文件非常有利于ULINK2仿真器的下载和调试,但是ADS的用户更习惯 ...
- Geoprocessor 使用
在AO中使用Geoprocessor(ESRI.ArcGIS.Geoprocessor) 1.观察arcmap中的使用方法,明确各参数意义. 2.arctoolbox中参数对应为features/fe ...