Post

๊ตฌ๋ช…๋ณดํŠธ lv2

๐ŸŒˆ๋ฌธ์ œ ๋งํฌ

Desktop View

Desktop View

๋‚ด๊ฐ€ ์ž‘์„ฑํ•ด๋ณธ ์ฝ”๋“œ (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 

Desktop View

์ •๋‹ต (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.
3D GIF