STUDY/Algorithm

[프로그래머스] LEVEL2 주식가격,python3,스택/큐

sinawi95 2019. 10. 29. 11:48
728x90

def solution(prices):
    len_p=len(prices)
    answer = [0]*len_p
    for i in range(len_p):
        tmp=prices[i+1:]
        for j in tmp:
            if prices[i]>j:
                answer[i]+=1
                break
            else :
                answer[i]+=1
    return answer


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

 

 


from collections import deque

def solution(prices):
    prices = deque(prices)
    answer = []
    len_pr = len(prices)
    while len_pr != 0:
        tmp = prices.popleft()
        len_pr -= 1 
        cnt = 0
        for i in range(len_pr):
            if tmp>prices[i]:
                cnt+=1
                break
            cnt+= 1
        
        answer.append(cnt)
    return answer


from collections import deque

def solution(prices):
    prices = deque(prices)
    answer = []
    len_pr = len(prices)
    while len_pr != 0:
        tmp = prices.popleft()
        len_pr -= 1 
        cnt = 0
        for i in range(len_pr):
            if tmp>prices[i]:
                cnt+=1
                break
            cnt+= 1
        answer.append(cnt)
    return answer


from collections import deque

def solution(prices):
    prices = deque(prices)
    answer = []
    len_pr = len(prices)
    
    while len_pr != 0:
        tmp = prices.popleft()
        len_pr -= 1 
        cnt = 0
        for j in prices:
            if tmp>j:
                cnt+=1
                break
            cnt+= 1
        answer.append(cnt)
    return answer


from collections import deque

def solution(prices):
    prices = deque(prices)
    answer = []
    len_pr = len(prices)
    
    for i in range(len_pr):
    #while len_pr != 0:
        tmp = prices.popleft()
        #len_pr -= 1 
        cnt = 0
        for j in prices:
            if tmp>j:
                cnt+=1
                break
            cnt+= 1
        answer.append(cnt)
    return answer