-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet881.py
More file actions
32 lines (30 loc) · 792 Bytes
/
leet881.py
File metadata and controls
32 lines (30 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Python TR
# Time:2021/8/27 9:12 上午
# coding = utf-8
class Solution(object):
def numRescueBoats(self, people, limit):
"""
:type people: List[int]
:type limit: int
:rtype: int
"""
if len(people)==1:
return 1
num = 0
peopleList = sorted(people)
i=0
# for i in range(0,len(people),2):
while i<len(peopleList):
if i==len(peopleList)-1:
num+=1
break
if peopleList[i]+peopleList[i+1]<=limit:
num+=1
i+=2
else:
break
if i<len(peopleList)-1:
num += len(peopleList)-i
return num
people = [5,1,4,2]
print(numRescueBoats(object,people,6))