This file contains 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 dfs(i, j, danji_num): | |
# 단지 0 아닐때마다 dict 카운트 올림 | |
if danji_num in danji_dict: | |
danji_dict[danji_num] += 1 | |
else: | |
danji_dict[danji_num] = 1 | |
danji_list[i][j] = 0 | |
visited[i][j] = True |
This file contains 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 dfs(i, j): | |
# 본인 0, visit = T로 바꿈 | |
visited[i][j] = 'T' | |
input_list[i][j] = 0 | |
for t in range(8): | |
# 현재 위치에서 8방향 탐색 | |
if -1 < i + x[t] < h and -1 < j + y[t] < w: | |
# 연결된 곳으로 이동 |
This file contains 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 * | |
import pytest | |
def solution(arr: list, target: int) -> int: | |
start_idx = 0 | |
end_idx = len(arr) | |
while 1: | |
mid_idx = (start_idx + end_idx) // 2 | |
mid_value = arr[mid_idx] |
This file contains 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(N): | |
_gap = 0 | |
prev = 0 | |
binary_list = [int(x) for x in bin(N)[2:]] | |
for idx, value in enumerate(binary_list): | |
if idx == len(binary_list) - 1: | |
if _gap == 0: | |
return 0 | |
else: | |
return _gap - 1 |
This file contains 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 solve(n: Int): Int = { | |
val input_seq = | |
Integer.toBinaryString(n).zipWithIndex.filter(_._1 == '1').map(_._2) | |
getGep(input_seq, input_seq.size - 1, 0) | |
} | |
@tailrec | |
def getGep(input_seq: IndexedSeq[Int], idx: Int, gap: Int): Int = { | |
if (idx == 0) { | |
if (gap == 0) 0 else gap - 1 |
This file contains 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(a, b, tc, tf): | |
b_minus_a = b - a | |
tf_minus_tca = tf - (tc * a) | |
# 해 2개이상이거나 없는 | |
if a == b: | |
if a + b == tf and tc == 2: | |
return '1 1' | |
return '-1' |
This file contains 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 re | |
def solution(dartResult): | |
st = {'S': 1, 'D': 2, 'T': 3} | |
token = {'#': -1, '*': 2, '': 1} | |
match_list = re.findall(r'(?P<num>\d+)(?P<st>[S,D,T]+)(?P<token>[*,#])?', dartResult) | |
for i, value in enumerate(match_list): |
This file contains 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(n, arr1, arr2): | |
result = [] | |
for i in range(n): | |
s = bin(arr1[i] | arr2[i])[2:].zfill(n) | |
result.append(s.replace("1", "#").replace("0", " ")) | |
return result |
This file contains 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 defaultdict | |
def solution(genres, plays): | |
result = [] | |
genre_data = defaultdict(list) | |
for genre, _index_and_plays in zip(genres, enumerate(plays)): | |
genre_data[genre].append(_index_and_plays) |