Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Tags more
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐ŸŒฒ์ž๋ผ๋‚˜๋Š”์ฒญ๋…„

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]ํฐ ์ˆ˜ ๋งŒ๋“ค๊ธฐ(Stack) ๋ณธ๋ฌธ

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œํ’€์ด

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]ํฐ ์ˆ˜ ๋งŒ๋“ค๊ธฐ(Stack)

JihyunLee 2019. 11. 26. 21:56
๋ฐ˜์‘ํ˜•

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ํฐ์ˆ˜ ๋งŒ๋“ค๊ธฐ๋ฅผ ํ’€์–ด๋ณด์•˜๋‹ค.

python ์—์„œ stack์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ตํ˜”๋‹ค

 

๋‚˜์˜ ์ฝ”๋“œ

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
def solution(number, k):
    stack = []
    remove =0 
 
    numlen = len(number)
 
    
    for i in range(0,numlen):
        idx = len(stack)-1
        while(idx >=0 and stack[idx]<int(number[i]) and remove<k):
            remove +=1
            stack.pop()
            idx = len(stack)-1
 
        stack.append(int(number[i]))
 
    if(remove<k):
        stack.pop()
    
    answer = ""
    
    for num in stack:
        answer += str(num)
 
    return(answer)
cs
๋ฐ˜์‘ํ˜•