Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 547 Bytes

881.md

File metadata and controls

36 lines (25 loc) · 547 Bytes

Boats to Save People

Description

link


Solution

See code


Code

O(nlogn) O(1)

class Solution:
    def numRescueBoats(self, people, limit):
        """
        :type people: List[int]
        :type limit: int
        :rtype: int
        """
        people.sort(reverse=True)
        
        i, j = 0, len(people) - 1
        while i <= j:
            if people[i] + people[j] <= limit: j -= 1
            i += 1
                 
        return i