728x90

나의 풀이
def solution(m, musicinfos):
musicinfos = [(x.split(',')) for x in musicinfos]
pool = []
temp, m = list(m), ''
for x in temp:
if x == '#':
m = m[:-1] + m[-1].lower()
else:
m += x
for start, end, name, melody in musicinfos:
start, end = list(map(int, start.split(':'))), list(map(int, end.split(':')))
duration = (end[0] - start[0]) * 60 + (end[1] - start[1])
notes = []
for x in melody:
if x =='#':
notes[-1] = notes[-1].lower()
else:
notes.append(x)
melody = ''
for i in range(duration):
melody += notes[i % len(notes)]
if m in melody:
pool.append((duration * -1, start, name))
if pool:
return sorted(pool)[0][2]
else:
return '(None)'
- 코드가 지저분한 경향이 있다.
- '#'을 제거하는 함수를 만들었으면 가독성이 더 좋았을 것
반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] [3차] 압축 (0) | 2022.06.18 |
|---|---|
| [프로그래머스/파이썬] 가장 큰 정사각형 찾기 (0) | 2022.06.18 |
| [프로그래머스/파이썬] 방문 길이 (0) | 2022.06.18 |
| [프로그래머스/파이썬] 쿼드압축 후 개수 세기 (0) | 2022.06.18 |
| [프로그래머스/파이썬] n^2 배열 자르기 (0) | 2022.06.17 |