LeetCode -- H-Index II
来源:互联网 发布:knn算法matlab代码 编辑:程序博客网 时间:2024/05/16 19:00
题目描述:
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
与H-Index的区别就是,这个数组是倒序排序好的。
思路:
省去了排序的步骤,直接从数组尾部向前遍历就可以了。
其余思路与H-index相同。
实现代码:
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
与H-Index的区别就是,这个数组是倒序排序好的。
思路:
省去了排序的步骤,直接从数组尾部向前遍历就可以了。
其余思路与H-index相同。
实现代码:
public class Solution { public int HIndex(int[] citations) { if(citations.Length == 0){ return 0; } var sum = 0; var j = 0; for(var i = citations.Length - 1;i >= 0; i--){ if(j < citations[i]){ sum ++; } j++; } return sum; }}
0 0
- Leetcode: H-Index II
- Leetcode: H-Index II
- [LeetCode]H-Index II
- H-Index II -- leetcode
- LeetCode H-Index II
- leetcode H-Index II
- [Leetcode]H-Index II
- [LeetCode] H-Index II
- LeetCode -- H-Index II
- [LeetCode]H-Index II
- LeetCode:H-Index II
- 【Leetcode】H-Index II
- Leetcode H-Index II
- leetcode:H-Index II
- LeetCode H-index and H-index II
- leetcode之H-index &&H-index II
- [leetcode] 275.H-Index II
- leetcode 275: H-Index II
- Libcap 文件格式
- LeetCode -- Game of Life
- AS3三种缩放方式的区别
- Hadoop集群(第7期)_Eclipse开发环境设置
- Sublime Text2配置C++编译环境
- LeetCode -- H-Index II
- Android 百度自动更新(升级)SDK的流程简介
- 【LeetCode-283】Move Zeroes(C++)
- javascript 数组的一些处理处理方法
- Android实现自定义带文字和图片的Button
- HTTP协议认识
- Performance Testing
- LeetCode -- Longest Increasing Subsequence
- 信心