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 typing import List | |
def decimal_to_binary(n: int) -> str: | |
if n == 0: | |
return '0' | |
result: str = "" | |
while (n > 0): | |
result = str(n % 2) + result | |
n //= 2 | |
return result |
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 heapq import heappush, heappop | |
from typing import List, Tuple | |
def solution(land: List[List[int]], height: int) -> int: | |
n = len(land) | |
visited: List[List[bool]] = [[False] * n for _ in range(n)] | |
total_cost = 0 | |
# 상, 우, 하, 좌 | |
directions: List[Tuple[int, int]] = [(-1, 0), (0, 1), (1, 0), (0, -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
from typing import List | |
def solution(s: str) -> List[int]: | |
inner = s[2:-2] | |
subset_strings = inner.split("},{") | |
subsets: List[List[int]] = [] | |
for subset_str in subset_strings: | |
number_strings = subset_str.split(",") | |
numbers = [int(num) for num in number_strings] |
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 functools import cmp_to_key | |
from typing import List | |
def solution(numbers:List[int]) -> str: | |
strs: List[str] = list(map(str, numbers)) | |
def compare(a: str, b: str) -> int: | |
if a + b > b + a: | |
return -1 | |
if a + b < b + 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 typing import List, Tuple | |
def solution(array: List[int], commands: List[Tuple[int, int, int]]) -> List[int]: | |
answer: List[int] = [] | |
for i, j, k in commands: | |
answer.append(sorted(array[i-1:j])[k-1]) | |
return answer |
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:str) -> str: | |
return "".join(sorted(s, reverse=True)) |
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 operator import itemgetter | |
def solution(strings, n): | |
alphabet_sorted = sorted(strings) | |
return sorted(alphabet_sorted, key = itemgetter(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 itertools import combinations_with_replacement | |
from collections import Counter | |
def solution(n, info): | |
maxdiff, max_comb = 0, {} | |
# 주어진 조합에서 각각의 점수 계산 | |
def calculate_score(combi): | |
ryon, apeach = 0, 0 | |
for score in range(1, 11): |
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(board, aloc, bloc): | |
ROW, COL = len(board), len(board[0]) # 게임판의 행, 열 저장 | |
DR, DC = [-1, 0, 1, 0], [0, 1, 0, -1] | |
# 주어진 위치가 유효한 위치인가? | |
def is_valid_pos(r, c): | |
return 0 <= r < ROW and 0 <= c < COL | |
# 재귀적 호출 | |
def recursive_func(alpha_pos, beta_pos, visited, step): |
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 backtrack(col_positions, current_row, board_size): | |
total_solutions = 0 | |
if current_row == board_size: | |
return 1 | |
for col in range(board_size): | |
col_positions[current_row] = col | |
for prev_row in range(current_row): | |
same_col = (col_positions[prev_row] == col) | |
same_diag = abs(col_positions[prev_row] - col) == current_row - prev_row | |
if same_col or same_diag: |
NewerOlder