[Python] 탐욕법_큰 수 만들기(23.09.30)

EunBi Na·2023년 10월 1일
0

링크텍스트

def solution(number, k):
    stack = [number[0]]
    for num in number[1:]:
        while len(stack) > 0 and stack[-1] < num and k > 0:
            k -= 1
            stack.pop()
        stack.append(num)
    if k != 0:
        stack = stack[:-k]
    return ''.join(stack)
profile
This is a velog that freely records the process I learn.

0개의 댓글