33716c71创建于 2023年6月21日历史提交
class Solution {
    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int boatsNeeded = 0;
        int lightIdx = 0;
        int heavyIdx = people.length-1;
        while (lightIdx <= heavyIdx) {
            if (people[lightIdx] + people[heavyIdx] <= limit) 
                lightIdx++;
            heavyIdx--;
            boatsNeeded++;
        }
        return boatsNeeded;
    }
}