알고리즘

알고리즘

[파이썬]프로그래머스 Lv.1 같은숫자는싫어

✅ 코드 def solution(arr): answer = [] for num in arr: if answer[-1:] == [num]: continue answer.append(num) return answer 빈 배열을 슬라이싱해도 IndexError가 발생하지 않습니다. 반대로 특정 위치의 값을 인덱싱 하면 IndexError가 발생합니다.

알고리즘

[파이썬]프로그래머스 Lv.1 달리기경주

✅ 코드 def solution(players, callings): players_dict = {player: idx for idx, player in enumerate(players)} for name in callings: idx = players_dict[name] front = players[idx - 1] players[idx - 1], players[idx] = players[idx], players[idx - 1] players_dict[name], players_dict[front] = idx - 1, idx return players 입력값의 제한은 다음과 같습니다. 5

알고리즘

[파이썬]프로그래머스 Lv.1 추억점수

✅ 코드 def solution(name, yearning, photos): answer = [] score = dict(zip(name, yearning)) for photo in photos: tmp = 0 for person in photo: if person in score: tmp += score[person] answer.append(tmp) return answer 문제가 제시하는 조건은 다음과 같습니다. 3

truezero
'알고리즘' 카테고리의 글 목록 (6 Page)