본문 바로가기

Algorithm/프로그래머스 연습 문제

프로그래머스 / 코딩 테스트 / 주식가격

문제 설명

 

 

문제 해결

 

굳이 스택, 큐를 이용하여 풀 필요는 없다고 생각했고 반복문을 이중으로 돌려 문제를 풀었다.

 

def solve(prices):
    res = []
    
    for i in range(len(prices)):
        count = 0
        prev = prices[i]
        for j in range(i+1, len(prices)):
            if prev <= prices[j]:
                count+=1
            else:
                if j < len(prices):
                    count+=1
                break
        res.append(count)
    return res

def solution(prices):
    answer = solve(prices)
    return answer