Участник:Polina Potapova/boats-to-save-people

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/boats-to-save-people

class Solution(object):
    def numRescueBoats(self, people, limit):
        """
        :type people: List[int]
        :type limit: int
        :rtype: int
        """
        people.sort()
        boats_count = 0
        while len(people) > 1:
            person_1 = people.pop()
            person_2 = people[0]
            if person_1 + person_2 <= limit:
                people.pop(0)
            boats_count += 1
 
        if len(people) == 1:
            boats_count += 1
 
        return boats_count