250x250
Link
๋‚˜์˜ GitHub Contribution ๊ทธ๋ž˜ํ”„
Loading data ...
Notice
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Data Science LAB

[Python] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต level2 (์ฃผ์‹๊ฐ€๊ฒฉ) ๋ณธ๋ฌธ

๐Ÿ“ Coding Test/Programmers

[Python] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต level2 (์ฃผ์‹๊ฐ€๊ฒฉ)

ใ…… ใ…œ ใ…” ใ…‡ 2023. 1. 19. 21:44
728x90

1. ๋ฌธ์ œ ์„ค๋ช…

์ดˆ ๋‹จ์œ„๋กœ ๊ธฐ๋ก๋œ ์ฃผ์‹๊ฐ€๊ฒฉ์ด ๋‹ด๊ธด ๋ฐฐ์—ด prices๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๊ฐ€๊ฒฉ์ด ๋–จ์–ด์ง€์ง€ ์•Š์€ ๊ธฐ๊ฐ„์€ ๋ช‡ ์ดˆ์ธ์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•˜์„ธ์š”.

 

 

 

 

2. ์ œํ•œ์‚ฌํ•ญ

  • prices์˜ ๊ฐ ๊ฐ€๊ฒฉ์€ 1 ์ด์ƒ 10,000 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.
  • prices์˜ ๊ธธ์ด๋Š” 2 ์ด์ƒ 100,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.

 

 

 

 

 

 

3. ๋‚ด ํ’€์ด

from collections import deque
def solution(prices):
    answer = []
    prices = deque(prices)
    n_prices = len(prices)
    
    for i in range(n_prices-1):
        n = prices.popleft()
        answer.append(n_prices-i-1)
        for idx,j in enumerate(prices):
            if n > j:
                answer.pop()
                answer.append(idx+1)
                break
        
    answer.append(0)   
    return answer

 

 

 

 

 

 

4. ๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด

def solution(prices):
    answer = [0] * len(prices)
    for i in range(len(prices)):
        for j in range(i+1, len(prices)):
            if prices[i] <= prices[j]:
                answer[i] += 1
            else:
                answer[i] += 1
                break
    return answer
728x90
Comments