[알고리즘 문제풀이] 같은 숫자는 싫어

ljkgb·2021년 4월 6일
0

알고리즘 문제풀이

✔문제

프로그래머스

✔내가 작성한 코드

def solution(arr):
    answer = []
    for index, num in enumerate(arr):
        if index == 0:
            answer.append(num)
        else:
            if arr[index] != arr[index-1]:
                answer.append(num)
            else:
                continue
            
    return answer

✔답안 예

def no_continuous(s):
    a = []
    for i in s:
        if a[-1:] == [i]: continue
        a.append(i)
    return a

✔Review

무릎 탁!치는 답안 ㅋㅋㅋㅋ 그래도 이번에 처음으로 enumerate를 써봐서 뭔가 뿌듯하다!

profile
🐹

0개의 댓글