首页 > 其他 > 详细

leetcode 274H-index

时间:2018-01-21 15:32:33      阅读:192      评论:0      收藏:0      [点我收藏+]
public int hIndex(int[] citations) {
        /*
        唠唠叨叨说了很多   其实找到一个数h,使得数组中至少有h个数大于等于这个数,
        其他N-h个数小于这个数,h可能有多个,求最大的那个
         */
        if (citations.length==0)
            return 0;
        //sort方法是将原数组排序,会改变原数组
        Arrays.sort(citations);
        int res = 0;
        for (int i = citations.length-1; i >=0 ; i--) {
            if (citations[i]>=citations.length-i)
            {
                res++;
            }
            else
                break;
        }
        return res;
    }

 

leetcode 274H-index

原文:https://www.cnblogs.com/stAr-1/p/8324264.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!