목록Algorithm/Programmers (76)
S E P H ' S
코딩테스트 연습 - 스킬트리 programmers.co.kr 풀이 1. 스킬트리 안의 각 스킬들이 선행스킬안에 있는지 파악. 있으면 다른 리스트 하나에 저장. 2. 그 리스트에서 enumerate를 해서 idx, 값 추출. 3. 그 스킬과, 그 스킬의 인덱스에 해당하는 선행스킬 리스트의 스킬과 같지 않으면 불가능한 스킬트리인 것. def solution(skill, skill_trees): skill = list(skill) flag = [] for i in skill_trees: post_skill_trees = [] for j in list(i): if j in skill: post_skill_trees.append(j) for idx, j in enumerate(post_skill_trees): i..
코딩테스트 연습 - 방문 길이 programmers.co.kr 문제보기 더보기 풀이 1. 델타 사용. 2. 가는 '길'이 중복되는 것은 제외 -> set 사용 3. set에 저장할 때, 좌표점이 아닌 가는 길을 저장. def solution(dirs): dir = {'U':(1,0), 'D':(-1,0), 'L':(0,-1), 'R':(0,1)} road = set() cr, cc = 0, 0 for d in dirs: nr, nc = cr + dir[d][0], cc + dir[d][1] if -5
코딩테스트 연습 - [3차] 방금그곡 방금그곡 라디오를 자주 듣는 네오는 라디오에서 방금 나왔던 음악이 무슨 음악인지 궁금해질 때가 많다. 그럴 때 네오는 다음 포털의 '방금그곡' 서비스를 이용하곤 한다. 방금그곡에서는 TV, programmers.co.kr 문제보기 더보기 풀이 musicinfos의 전처리가 필요하다. 1. 코드 중에 #이 붙은 음들은 소문자로 Replace 2. 노래 시작시간, 종료시간으로 재생시간을 구하고 시작. 3. 재생시간이 음보다 짧은 경우 4. 재생시간이 음보다 긴 경우 3, 4의 경우에 맞게 melody를 구성하고, m이 melody에 포함된다면 answer에 추가한다. 이 때, 정답의 조건에 '조건에 일치하는 음악이 여러 개일 때에는 재생된 시간이 제일 긴 음악제목을 반환..
코딩테스트 연습 - [3차] 압축 TOBEORNOTTOBEORTOBEORNOT [20, 15, 2, 5, 15, 18, 14, 15, 20, 27, 29, 31, 36, 30, 32, 34] programmers.co.kr 문제보기 더보기 def solution(msg): answer = [] dic = {} for i in range(26): dic[chr(65+i)] = i + 1 w, c = 0, 0 while True: c += 1 if c == len(msg): answer.append(dic[msg[w:c]]) break if msg[w:c+1] not in dic: dic[msg[w:c+1]] = len(dic) + 1 answer.append(dic[msg[w:c]]) w = c retur..