공부/코딩테스트

[프로그래머스] 주식가격(파이썬)

ghhong 2021. 1. 22. 21:04

나의 답 :

def solution(prices):
    answer = []
    l=len(prices)
    cnt=0
    for i in range(l):
        for j in range(i+1,l):
            cnt+=1
            if prices[i]>prices[j]:
                break
        answer.append(cnt)
        cnt=0
    return answer

 

다른 사람의 답 :

from collections import deque
def solution(prices):
    answer = []
    prices = deque(prices)
    while prices:
        c = prices.popleft()

        count = 0
        for i in prices:
            if c > i:
                count += 1
                break
            count += 1

        answer.append(count)

    return answer

 

같은 O(n^2)일 듯