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(skill, skill_trees): | |
skill_set = set(skill) | |
skill_list = list(skill) | |
count = 0 | |
for string in skill_trees: | |
idx = 0 | |
for i in range(len(string)): | |
if string[i] in skill_set: | |
# 순서상 가능한 스킬트리인지 확인 | |
if string[i] == skill_list[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
from datetime import datetime | |
# 문자열을 sec로 변환하는 메소드 | |
def convert_to_seconds(time): | |
time = map(int, time.split(":")) | |
result = 0 | |
for t, sec in zip(time, [3600, 60, 1]): | |
result += t * sec | |
return result; | |
# sec를 문자열로 반환하는 메소드 |
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 copy import deepcopy | |
from itertools import combinations | |
import bisect | |
def solution(info, query): | |
answer = [] | |
table = dict() | |
tmp = [ | |
["cpp","java","python","-"], | |
['backend','frontend','-'], | |
['junior','senior','-'], |
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 | |
from collections import defaultdict | |
def solution(orders, course): | |
orders = [sorted(i) for i in orders] | |
counter = defaultdict(int) | |
max_count = defaultdict(int) | |
for order in orders: | |
for c in course: | |
if len(order) < c: | |
continue |
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 re | |
def solution(new_id): | |
# 1. 소문자 치환 | |
new_id = new_id.lower() | |
# 2. 알파벳 소문자, 숫자, -, _, . 빼고 제거 | |
new_id = re.sub(r"[^a-z0-9\-\_\.]","",new_id) | |
# 3. . 두 개 이상이면 하나로 치환 | |
new_id = re.sub(r"[\.]+", ".", new_id) | |
# 4. 마침표가 처음이나 끝에 있으면 제거 | |
if new_id.startswith("."): new_id = new_id[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 collections import Counter | |
def solution(a): | |
# a 배열 element 각 원소의 등장횟수를 센다. | |
elements = Counter(a) | |
answer = -1 | |
# a에 있는 각 원소 k를 기준으로 | |
# k값을 기준으로 스타수열을 만들 수 있는지 검증한다. | |
for k in elements.keys(): | |
# k의 등장횟수가 스타수열에 사용된 공통인자 횟수보다 작거나 같으면 |
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 Counter | |
def solution(s): | |
# 0 개수, 반복 횟수를 저장 | |
zeros, cnt = 0, 0 | |
while s != "1": | |
# 횟수 카운트 | |
cnt += 1 | |
# 제거한 0의 개수 저장 | |
zeros += Counter(s)['0'] | |
# 1의 개수를 정수로 변환 -> bin()으로 이진수 변환 -> str로 문자열 변환. |
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
class Solution: | |
def merge(self, intervals: List[List[int]]) -> List[List[int]]: | |
# 겹치는 구간파악을 위해, 먼저 정렬 | |
merged = [] | |
for arr in sorted(intervals, key = lambda x: x[0]): | |
# arr의 시작점이 구간 안에 있는 경우 | |
if merged and arr[0] <= merged[-1][1]: | |
# arr의 끝점과 merged 끝점 중 더 긴 것을 merged 끝점에 업데이트 | |
merged[-1][1] = max(merged[-1][1], arr[1]) | |
else: |
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 defaultdict | |
import heapq | |
class Solution: | |
def networkDelayTime(self, times: List[List[int]], N: int, K: int) -> int: | |
# 1. 모든 노드가 신호를 받을 수 있는가? | |
# 2. 모든 노드에 도달할 때까지의 시간은? | |
# = 가장 오래 걸리는 노드까지의 최단거리 = 다엑스트라 알고리즘으로 해결 가능 | |
# 단방향 = 인접연결리스트로 그래프 정보 구현 | |
graph = defaultdict(list) |
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
class Solution: | |
def subsets(self, nums: List[int]) -> List[List[int]]: | |
# 트리 구조의 dfs로 해결하기 | |
result = [] | |
def dfs(idx, path): | |
result.append(path) | |
# idx 순서대로 경로를 만들면서 dfs 연산 | |
for next_idx in range(idx, len(nums)): | |
dfs(next_idx + 1, path + [nums[next_idx]]) | |