From d91bb106884da0ab726e17a05fec04235264ad0e Mon Sep 17 00:00:00 2001 From: yu iseo <97578465+yuiseo@users.noreply.github.com> Date: Sat, 30 Nov 2024 22:38:38 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20#6=20=ED=81=B0=20=EC=88=98=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0=20-=20=EC=9C=A0=EC=9D=B4=EC=84=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\234\240\354\235\264\354\204\234.py" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260/\354\234\240\354\235\264\354\204\234.py" diff --git "a/greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260/\354\234\240\354\235\264\354\204\234.py" "b/greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260/\354\234\240\354\235\264\354\204\234.py" new file mode 100644 index 0000000..99f0a01 --- /dev/null +++ "b/greedy/\355\201\260 \354\210\230 \353\247\214\353\223\244\352\270\260/\354\234\240\354\235\264\354\204\234.py" @@ -0,0 +1,18 @@ +def solution(number, k): + stack = [] + for num in number: + while stack and stack[-1] < num and k > 0: + stack.pop() + k -= 1 + stack.append(num) + + # 남은 k만큼 뒤에서 제거 + if k > 0: + stack = stack[:-k] + + return ''.join(stack) + + +## 실패 코드 - 시간초과 시간복잡도 O(n^(k+1)) +# arr = [int(''.join(comb)) for comb in combinations(number, len(number)-k)] +# answer = str(max(arr))