프로그래머스. 같은 숫자는 싫어 파이썬 풀이

minan·2021년 6월 24일
0

프로그래머스

목록 보기
42/92

프로그래머스. 연습문제. Level 1. 같은 숫자는 싫어 파이썬 풀이

문제링크 https://programmers.co.kr/learn/courses/30/lessons/12906

def solution(arr):
    answer = []
    
    # 첫 문자를 미리 넣어두어 리스트 인덱스 오류를 방지, 결과는 같음
    answer.append(arr[0])
    
    for num in arr: 
        # 결과의 마지막 숫자와 현재 숫자가 같다면 continue
        if answer[-1] == num:
            continue
        else: 
            answer.append(num)
    
    return answer
profile
https://github.com/minhaaan

0개의 댓글