0
点赞
收藏
分享

微信扫一扫

H 指数 II

村里搬砖的月野兔 2021-09-21 阅读 22
今日算法
题目描述
示例:
题目分析
  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 条评论