#달리기 경주
def solution(players, callings):
for k in callings:
ch=players.index(k)
players[ch-1],players[ch]=players[ch],players[ch-1]
answer=players
return answer
>>시간초과
def solution(players, callings):
answer = []
dic_players = {}
dic_lank = {}
for idx, i in enumerate(players):
dic_players[i] = idx
dic_lank[idx] = i
for i in callings:
cur_idx = dic_players[i]
dic_players[i] = cur_idx - 1
dic_players[dic_lank[cur_idx-1]] = cur_idx
dic_lank[cur_idx] = dic_lank[cur_idx - 1]
dic_lank[cur_idx - 1] = i
answer = list(dic_lank.values())
return answer
#추억 점수
def solution(name, yearning, photo):
answer = [0 for i in range(len(photo))]
for i in range(len(photo)):
for j in name:
answer[i]+=(photo[i].count(j)*yearning[name.index(j)])
return answer
'코딩테스트 | python > 프로그래머스' 카테고리의 다른 글
| [프로그래머스 | python] 전화번호 목록 (0) | 2024.02.06 |
|---|---|
| [프로그래머스 | python] 완주하지 못한 선수 (1) | 2024.02.06 |
| [프로그래머스 | python] 다리를 지나는 트럭 >> 다시 풀어보기 (0) | 2024.02.06 |
| [프로그래머스 | python] 덧칠하기 (0) | 2023.10.20 |
| [프로그래머스 | python] 바탕화면 정리 (0) | 2023.10.20 |