본문 바로가기

CodingTest/Level2

[연습] 코딩테스트 - 탑

코딩테스트 연습

  • programmers.co.kr

def solution(heights):
    tmp_list = []
    answer = []
    for i,x in enumerate(heights):
        tmp_list += [i]

    while len(heights) > 1:
        cnt = len(heights)
        tmp = heights.pop()
        cnt -= 1
        for y in heights[::-1]:
            if y > tmp:
                answer += [tmp_list[cnt]]
                break    
            else:
                cnt -=1
        else:
            answer += [0]

    answer +=[0]
    answer = [x for x in answer[::-1]]

    return answer
반응형