-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0306.py
More file actions
25 lines (24 loc) · 859 Bytes
/
0306.py
File metadata and controls
25 lines (24 loc) · 859 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
#https://school.programmers.co.kr/learn/courses/30/lessons/42885
#문제 조건좀 제대로 읽자...보트에 최대 2명인데 2명이상 태울 수 있는줄 알고 계속 풀고 있었다...
#list로 풀어도 ㄱㅊ고 deq으로 풀어도 상관없다. 주의할 점은 두개를 pop하는 경우가 있으므로 empty deque를 조심해서 조건 설정할 것
from collections import deque
def solution(people, limit):
count = 0
people.sort()
q = deque(people)
w = 0
cnt = 0
while q:
if len(q) >= 2:
if q[0] + q[-1] <= limit:
q.pop()
q.popleft()
count += 1
elif q[0] + q[-1] > limit:
q.pop()
count += 1
else:
if q[0] <= limit:
q.pop()
count += 1
return count