Leetcode H-Index
来源:互联网 发布:老虎伊甸园 知乎 编辑:程序博客网 时间:2024/06/05 02:53
题意:
计算H-Index,即在数列中至少有x个数大于x。
思路:
先由大到小排序,然后判断a[i]-i是否大于等于0,如果大于等于0,则表明至少有i个数大于i。
代码如下:
int cmp(const void *a,const void *b){ return -(*(int*)a-*(int*)b);}int hIndex(int* citations, int citationsSize) { int i=0; int ans=0; if(citationsSize==0){ return 0; } qsort(citations,citationsSize,sizeof(int),cmp); ans=0; for(i=0;i<citationsSize;++i){ if(citations[i]-i-1>=0){ ans=i+1; } } return ans;}
0 0
- Leetcode 274 : H-index
- leetcode H-Index
- [leetcode][sort] H-Index
- 【leetCode】H-Index
- Leetcode: H-Index
- Leetcode: H-Index II
- leetcode 274: H-Index
- [leetcode] 274.H-Index
- leetcode 之 H-index
- LeetCode: H-Index
- leetcode H-index 2
- Leetcode: H-Index
- Leetcode: H-Index II
- leetcode: H-Index
- [LeetCode 274] H-index
- [LeetCode]H-Index
- [LeetCode]H-Index II
- H-Index -- leetcode
- [OpenGL系列] VS2015+FreeGLUT+GLEW
- c语言 %-5d问题
- HDU 1233 还是畅通工程
- matlab使用的小技巧
- UVAL 7327
- Leetcode H-Index
- 动态规划
- Android Studio导入第三方类库的方法
- C#控制台基础 ??合并运算符
- 【面试总结】腾讯MIG一面
- 如何提高MSP430 C语言代码的执行效率
- 第一次机房收费系统【总结】——结账
- 组合数打表(小模板)
- 给定一个序列,输出所有满足栈规则的所有情况