Skip to content

Instantly share code, notes, and snippets.

View silver-ring-data's full-sized avatar

Silver Ring silver-ring-data

  • 01:25 (UTC +09:00)
View GitHub Profile
def solution(X, Y):
# ๊ณตํ†ต์  ์ฐพ๊ณ 
# ํฐ์ˆœ์„œ๋Œ€๋กœ ๋‚˜์—ด
x_counts = [0] * 10
y_counts = [0] * 10
for current_x in X :
x_counts[int(current_x)] += 1
for current_y in Y :
from collections import deque
def solution(priorities, location):
queues = deque((index,priority) for index, priority in enumerate(priorities))
count = 0
while queues:
highest_priority = max(queues, key=lambda x: x[1])[1]
current_index,current_priority = queues.popleft()
def solution(cards1, cards2, goal):
for goal_card in goal :
issame = False
if cards1:
if goal_card == cards1[0] :
cards1.pop(0)
issame = True
if cards2:
if goal_card == cards2[0] :
def solution(progresses, speeds):
ends = []
for prog, speed in zip(progresses, speeds) :
end = (100 - prog)//speed
end_remain = (100 - prog)%speed
if end_remain :
end += 1
ends.append(end)
answer = []
def function(N,K) :
people = [num+1 for num in range(N)]
result = []
current_index = 0
while people:
current_index = (current_index + K-1) % len(people) # ์ถœ๋ฐœ ์ธ๋ฑ์Šค ๋ฐ”๊พธ๊ธฐ
result.append(people.pop(current_index))
def solution(n, k, cmd):
results = ['O'] * n
deletes = [] # (์ด์ „ํ–‰, ํ˜„์žฌํ–‰, ๋‹ค์Œํ–‰)์˜ ํŠœํ”Œ ๋ฆฌ์ŠคํŠธ์ž„
# n = ์ฒ˜์Œ ํ‘œ์˜ ํ–‰ ๊ฐœ์ˆ˜
# k = ํ˜„์žฌ ์œ„์น˜
table = {i: [i - 1, i + 1] for i in range(n)} # {ํ˜„์žฌํ–‰: [์ด์ „ํ–‰, ๋‹ค์Œํ–‰]}
table[0][0] = None
table[n - 1][1] = None
def solution(board, moves):
buckets = []
answer = 0 # ์ธํ˜• ํ„ฐ์ง„ ํšŸ์ˆ˜
for move in moves :
col = move - 1
for row in range(len(board)):
doll_number = board[row][col]
if doll_number : #0์ด ์•„๋‹๋•Œ
def solution(prices):
n = len(prices)
answer = [0] * n
for i in range(n):
# ํ˜„์žฌ ๊ฐ€๊ฒฉ๋ณด๋‹ค ๋’ค์— ์žˆ๋Š” ๊ฐ€๊ฒฉ๋“ค์„ ํ•˜๋‚˜์”ฉ ํ™•์ธ
for j in range(i + 1, n):
# 1์ดˆ๊ฐ€ ์ง€๋‚ฌ์œผ๋ฏ€๋กœ ์‹œ๊ฐ„์„ ๋”ํ•จ
answer[i] += 1
def solution(s):
stack = []
for char in s:
# ์Šคํƒ์— ๋ฌด์–ธ๊ฐ€ ์žˆ๊ณ , ๋งจ ์œ„ ๊ธ€์ž๊ฐ€ ํ˜„์žฌ ๊ธ€์ž์™€ ๊ฐ™๋‹ค๋ฉด? -> ์ง๊ฟ ๋ฐœ๊ฒฌ!
if stack and stack[-1] == char:
stack.pop()
# ๊ทธ ์™ธ์˜ ๋ชจ๋“  ๊ฒฝ์šฐ (์Šคํƒ์ด ๋น„์—ˆ๊ฑฐ๋‚˜, ๊ธ€์ž๊ฐ€ ๋‹ค๋ฅด๊ฑฐ๋‚˜) -> ์ผ๋‹จ ์Œ“๊ธฐ
else:
stack.append(char)
def is_able(s):
pairs = {')': '(', ']': '[', '}': '{'}
stack = []
for current_s in s:
# 1. ์—ฌ๋Š” ๊ด„ํ˜ธ์ธ ๊ฒฝ์šฐ
if current_s in pairs.values():
stack.append(current_s)
# 2. ๋‹ซ๋Š” ๊ด„ํ˜ธ์ธ ๊ฒฝ์šฐ