khoitran.lord
Junior Member
Code:
class Solution(object):
def numRescueBoats(self, people, limit):
"""
:type people: List[int]
:type limit: int
:rtype: int
"""
if (len(people) == 1): return 1
boatNum = 0
people.sort()
sortedPeople = people
left, right = 0, len(sortedPeople) -1
while left < right :
if sortedPeople[left] + sortedPeople[right] <= limit:
print(left, right)
left += 1
right -= 1
boatNum += 1
else:
print(left, right)
right -= 1
boatNum += 1
if left == right:
boatNum += 1
return boatNum