L1 : 같은 숫자는 싫어 Python

jhyunn·2023년 1월 15일
0

Programmers

목록 보기
15/69

L1 : 같은 숫자는 싫어 Python

https://school.programmers.co.kr/learn/courses/30/lessons/12906

def solution(arr):
    answer = []
    for i in arr:
        answer.append(i)
        try:
            if answer[-2] == answer[-1]:
                answer.pop()
        except:
            continue
    return answer

스택/큐 문제는 빈 리스트(스택/큐)에 채워나가면서 비교하는게 속도를 줄이는 팁이다.

profile
https://github.com/Sungjeonghyun

0개의 댓글