This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
def solution(n, k): | |
# 1번부터 n번까지 번호 배열 | |
numbers = list(range(1, n+1)) | |
# 총 사람 수 | |
length = len(numbers) | |
result = [] | |
while len(result) != length: | |
# 앞자리부터 조건에 부합하는 숫자 찾기 = 나머지 숫자들을 가지고 경우의 수 확인. | |
n -= 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(s): | |
return " ".join([i.capitalize() for i in s.split(" ")]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def solution(a): | |
# 맨 앞, 맨 뒷 풍선은 어떻게든 남길 수 있다. | |
# 가운데에 있는 풍선은, 자신을 둘러싼 풍선의 최솟값보다 작다면 남을 수 있다. | |
answer = 0 | |
left, right = math.inf, math.inf | |
maps = [[0 for _ in range(len(a))] for _ in range(2)] | |
# 인접한 풍선 중 번호가 큰 풍선을 터트린다. | |
# 왼쪽 기준으로, 번호가 작은 풍선을 남기는 경우 | |
for i in range(len(a)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain | |
def solution(n): | |
maps = [[0 for _ in range(n)] for _ in range(n)] | |
y, x = -1, 0 | |
number = 1 | |
for i in range(n): | |
for j in range(i, n): | |
if i % 3 == 0: | |
y += 1 | |
elif i % 3 == 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
n = int(sys.stdin.readline()) | |
# table[위치] = 이 위치까지 왔을 때 마실 수 있는 최댓값. | |
# i-1, i-2 둘 다 마신 경우. = table[i-1] | |
# i-1잔을 마시지 않는 경우 = table[i-2] + arr[i] | |
# i-2잔을 마시지 않은 경우 = table[i-3] + arr[i-1] + arr[i] | |
arr = [0,0,0] | |
for i in range(n): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def solution(board): | |
def bfs(start): | |
queue = deque() | |
queue.append((start, 0)) | |
visited = set() | |
while queue: | |
coord, cnt = queue.popleft() | |
# 현재 비행기 위치좌표 저장 | |
visited.add(tuple(coord)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def solution(matrix_sizes): | |
# table[start][end] = 인덱스 start ~ end 까지의 연산 최솟값. | |
table = [[math.inf for _ in range(len(matrix_sizes))] for _ in range(len(matrix_sizes))] | |
# start와 end가 동일한 경우는 연산하지 않으므로 0으로 설정. | |
for idx in range(len(matrix_sizes)): | |
table[idx][idx] = 0 | |
for gap in range(1, len(matrix_sizes)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from collections import deque | |
def solution(board): | |
def bfs(start): | |
# table[y][x] = 해당 위치에 도달하는 최솟값. | |
table = [[math.inf for _ in range(len(board))] for _ in range(len(board))] | |
# 진행 방향. 위 - 0, 왼쪽 - 1, 아래 = 2, 오른쪽 = 3 | |
dirs = [(-1,0),(0,-1),(1,0),(0,1)] | |
queue = deque([start]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import permutations | |
def solution(expression): | |
def calculate(priority, idx, expression): | |
# 연산자 우선순위 끝까지 도착한 경우 | |
if idx == len(priority)-1: | |
# 연산 결과를 문자열로 리턴 | |
return str(eval(expression)) | |
return priority[idx].join([str(eval(calculate(priority, idx+1, e))) for e in expression.split(priority[idx])]) | |
# 연산자 저장 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(numbers, hand): | |
pad = { | |
1:(0,0), 2:(0,1), 3:(0,2), | |
4:(1,0), 5:(1,1), 6:(1,2), | |
7:(2,0), 8:(2,1), 9:(2,2), | |
0:(3,1) | |
} | |
left, right = {1,4,7}, {3,6,9} | |
left_pos, right_pos = (3,0), (3,2) | |
answer = [] |