https://programmers.co.kr/learn/courses/30/lessons/42883
Code
1
2
3
4
5
6
7
8
9
10
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)
Complexity
- $n$ = len(
number
)
PREVIOUSEtc