본문 바로가기

전체 글92

[python] 완주하지 못한 선수 문제 출처 완주하지 못한 선수 풀이 def solution(participant, completion): answer = '' dict_participant = {} for name in completion: if dict_participant.get(name, None): dict_participant[name] += 1 else: dict_participant[name] = 1 for name in participant: if dict_participant.get(name, None): if dict_participant[name]: dict_participant[name] -= 1 else: answer = name break else: answer = name break return answer 2019. 9. 3.
[python] 추석 트래픽 문제 출처 추석 트래픽 풀이 def solution(lines): logs = [] for line in lines: _, done, time = line.split() h, m, s = done.split(&#39;:&#39;) end = (int(h)*60*60 + int(m)*60 + float(s))*1000 logs.append((end-float(time[:-1])*1000+1, end)) length = len(logs) max_ = 1 for i in range(length-1): cnt = 1 for j in range(i+1, length): if logs[j][1] - logs[i][1] >= 4000: break if logs[j][0] - logs[i][1] < 1000: cnt .. 2019. 9. 3.
[python] 무지의 먹방 라이브 문제 출처 무지의 먹방 라이브 풀이 def solution(food_times, k): times = {} for idx, time in enumerate(food_times): if time in times: times[time].append(idx) else: times[time] = [idx] len_foods = len(food_times) cycle = 0 for time in sorted(times): if k - (len_foods*(time-cycle)) >= 0: k -= len_foods*(time-cycle) len_foods -= len(times[time]) cycle += time-cycle else: k %= len_foods for i in times: if i >= time.. 2019. 9. 3.
[python] 단어 변환 문제 출처 단어 변환 풀이 def dfs(now, target, words, history=[], depth=0): global min_ print(now, history) if now == target: min_ = min(min_, depth) if depth >= min_: return for word in words: if word in history: continue cnt = 0 for i in range(len(target)): if word[i] != now[i]: cnt += 1 if cnt > 1: break if cnt == 1 and word not in history: history.append(word) dfs(word, target, words, history, depth+1).. 2019. 9. 1.