美文网首页
275. H-Index II

275. H-Index II

作者: FlynnLWang | 来源:发表于2016-12-28 08:26 被阅读0次

Question

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
Hint:
Expected runtime complexity is in O(log n) and the input is sorted.


Code

public class Solution {
    public int hIndex(int[] citations) {
        if (citations == null || citations.length == 0) return 0;
        int n = citations.length;
        
        for (int i = 0; i < n; i++) {
            if (citations[i] >= n - i) return n - i;
        }
        return 0;
    }
}

Solution

与274的解法1一样。

相关文章

  • 2019-02-05

    LeetCode 275. H-Index II Description Given an array of ci...

  • 275. H-Index II

    Question Follow up for H-Index: What if the citations arr...

  • 275. H-Index II

  • [Leetcode]275. H-Index II

    一、问题链接:https://leetcode.com/problems/h-index-ii/descripti...

  • 274. H-Index, 275. H-Index II

    274 就先sort一下,再遍历一遍从高到低排序,然后从左向右扫。如果一个数的值大于等于他的index + 1,则...

  • 274&275. H-Index

    274 Given an array of citations (each citation is a non-n...

  • Leetcode - H-Index II

    My code: 用 Binary search 找最接近target并且 >= target 的 那个index...

  • 【leetcode】 H-Index II

    1、题目描述 Given an array of citations **sorted in ascending ...

  • 275. H指数 II

    给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列。编写一个方法,计算出研究者的 h...

  • Leetcode 275. H指数 II

    题目 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列。编写一个方法,计算出研究者...

网友评论

      本文标题:275. H-Index II

      本文链接:https://www.haomeiwen.com/subject/ahfyvttx.html