Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

짱이 될거야

프로그래머스(스택/큐): 같은 숫자는 싫어 본문

알고리즘

프로그래머스(스택/큐): 같은 숫자는 싫어

짱이 되었어 2022. 10. 3. 08:20

배열 arr에서 연속적으로 나타나는 숫자는 제거하고 남은 수들을 return 하는 solution 함수를 완성해 주세요.

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

def solution(arr):
    answer = []
    
    for num in arr:
        if not answer:
            answer.append(num)
        elif num == answer[-1]:
            pass
        else:
            answer.append(num)
    return answer
Comments