Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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
- ๊ทธ๋ฆฌ๋
- ํ๋ก๊ทธ๋๋จธ์ค
- CSS
- ๋ชจ๊ฐ์ฝ
- ๋๋ฆผ์ฝ๋ฉ
- HTML
- ๋ ธ๋ง๋์ฝ๋
- ํ ์ดํ๋ก์ ํธ
- Python
- heapq
- ํ์ด์ฌ
- react
- Til
- ์ฝ๋ฉ
- mongodb
- node.js
- JS
- KDT
- error
- ์๊ณ ๋ฆฌ์ฆ
- fe
- ํฌ๋กค๋ง
- ์ฝ๋ฉ์ ํ
- ๋ฐฑ์ค
- ๊ฐ๋ฐ
- javascript
- ๊ตญ๋น์ง์
- ํ๋ก ํธ์๋
- ํ๋ก์ ํธ
- ์ฝ๋ฉํ ์คํธ
Archives
- Today
- Total
๐ฑ → ๐ณ
[ํ๋ก๊ทธ๋๋จธ์ค] ํฐ ์ ๋ง๋ค๊ธฐ - python ๋ณธ๋ฌธ
728x90
์ฝ๋
์๊ฐ์ด๊ณผ ์ฝ๋
from itertools import combinations
def solution(number, k):
answer = ''
arr = list(combinations(number, len(number)-k))
for i in max(arr):
answer += i
return answer
combination ์์ฒด๊ฐ ๋ฌด๋ฆฌ์ธ ๋ฏ ํ๋ค
์ ๋ต ํ์ด 1
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)
์ ๋ต ํ์ด 2
from collections import deque
def solution(number, k):
q = deque()
stack = deque()
for n in number:
q.append(n)
while q and k:
while stack and stack[-1] < q[0]:
stack.pop()
k -= 1
if not k:
break
stack.append(q.popleft())
while k and stack:
stack.pop()
k -= 1
return "".join(stack + q)
728x90
'Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ - python (0) | 2023.09.28 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ชจ์์ฌ์ - python (0) | 2023.09.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์จ์ด ์๋ ์ซ์์ ๋ง์ - python (0) | 2023.09.15 |
[Baekjoon] 11718. ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ - python (0) | 2023.09.14 |
[ํ๋ก๊ทธ๋๋จธ์ค] ํผ๋ก๋ - python (0) | 2023.09.07 |