Skip to content

Commit dddbd8d

Browse files
yongjun-0903unknown
andauthored
[오늘의 알고리즘] 구명보트 (#63)
Co-authored-by: unknown <Administrator@SKCC20N00129.SKCC.NET>
1 parent e750210 commit dddbd8d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

yongjun-0903/구명보트.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from collections import deque
2+
3+
def solution(people, limit):
4+
people.sort()
5+
6+
queue = deque(people)
7+
count = 0
8+
boat = []
9+
10+
while queue:
11+
person = queue.popleft()
12+
if sum(boat) + person <= limit and len(boat) <= 2:
13+
boat.append(person)
14+
else:
15+
count += 1
16+
boat = []
17+
if boat:
18+
count += 1
19+
return count

0 commit comments

Comments
 (0)