아직 파이썬 for문이 익숙치 않다.

C언어가 편하다...

def solution(heights):
    answer = [ 0 for x in heights]
    current_v=0
    heights.reverse()
    for i, v in enumerate(heights):
        current_v=heights[i]
        for j in range(i+1, len(heights)):
            if heights[j]>current_v:
                answer[i] = len(heights) - j
                break
    answer.reverse()
    print(answer)
            
    return answer

 

타인의 풀이

def solution(h):
    ans = [0] * len(h)
    for i in range(len(h)-1, 0, -1):
        for j in range(i-1, -1, -1):
            if h[i] < h[j]:
                ans[i] = j+1
                break
    return ans

 

+ Recent posts