๊ตฌ๋ช ๋ณดํธ lv2
๐๋ฌธ์ ๋งํฌ
๋ด๊ฐ ์์ฑํด๋ณธ ์ฝ๋ (X)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def solution(people, limit):
end = 0
people.sort()
interval_sum = 0
cnt = 0
for start in range(len(people)):
while interval_sum <= limit and end < len(people):
interval_sum += people[end]
end += 1
if interval_sum > limit:
end -= 1
interval_sum -= people[end]
interval_sum -= people[start]
cnt += 1
return cnt
์ ๋ต (O)
1
2
3
4
5
6
7
8
9
10
11
12
13
def solution(people, limit):
people.sort()
cnt = 0
start, end = 0, len(people)-1
while start <= end:
if people[start] + people[end] <= limit:
start += 1
end -= 1
cnt += 1
return cnt
์ฐธ๊ณ
https://only-wanna.tistory.com/entry/ํ์ด์ฌ-ํ๋ก๊ทธ๋๋จธ์ค-๊ตฌ๋ช ๋ณดํธ-ํ์ด
This post is licensed under CC BY 4.0 by the author.