본문 바로가기
Coding Test

[CT] Programmers 배열 만들기4 Python3 ver.

by Luciditas 2024. 3. 10.
728x90

 

[나의 풀이]

def solution(arr):
    stk = []
    i = 0
    while i < len(arr):
        if len(stk) == 0:
            stk.append(arr[i])
            i += 1        
        elif len(stk) > 0 and stk[-1] < arr[i]:            
            stk.append(arr[i])
            i +=1
        elif len(stk) > 0 and stk[-1] >= arr[i]:
            stk.pop()
    return stk
728x90