• Leetcode 881 救生艇 双指针


     

      JAVA:

        public final int numRescueBoats(int[] people, int limit) {
            if (people == null || people.length == 0) return 0;
            Arrays.sort(people);
            int len = people.length, begin = 0, end = len - 1, re = 0;
            while (begin <= end) {
                if (people[end] + people[begin] <= limit) begin++;
                end--;
                re++;
            }
            return re;
        }

      JS:

    var numRescueBoats = function (people, limit) {
        if (!people || !people.length) return 0;
        let len = people.length, begin = 0, end = len - 1, re = 0;
        people.sort(function (a, b) {
            return a - b
        });
        while (begin <= end) {
            if (people[end] + people[begin] <= limit) begin++;
            end--;
            re++
        }
        return re;
    };

    当你看清人们的真相,于是你知道了,你可以忍受孤独
  • 相关阅读:
    购物网站被p.egou.com强制恶意劫持
    css下拉菜单
    StringToInt
    JframeMaxSize
    frameMaxSize
    inputChar
    英语要求
    sciAndSubject
    fileRename
    tensorflowOnWindows
  • 原文地址:https://www.cnblogs.com/niuyourou/p/14673426.html
Copyright © 2020-2023  润新知