H 指数 II

阅读 22

2021-09-21

题目描述
示例:
题目分析
  1. h指数小于等于数组元素个数
  2. 数组是有序的
  3. 求h指数也就是求[i, citations.length]中citations[i] > h的边界
思路:
代码实现:
class Solution {
    public int hIndex(int[] citations) {
        int len = citations.length;
        int h = 0;
        for (int i = len - 1; i >= 0; i--) {
            if (citations[i] > h) {
                h++;
            } else {
                break;
            }
        }
        return h;
    }
}

精彩评论(0)

0 0 举报