๐ Coding Test/Programmers
[Python] ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉํ ์คํธ ์ฐ์ต level2 (์ฃผ์๊ฐ๊ฒฉ)
ใ
ใ
ใ
ใ
2023. 1. 19. 21:44
728x90
1. ๋ฌธ์ ์ค๋ช
์ด ๋จ์๋ก ๊ธฐ๋ก๋ ์ฃผ์๊ฐ๊ฒฉ์ด ๋ด๊ธด ๋ฐฐ์ด prices๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ๊ฐ๊ฒฉ์ด ๋จ์ด์ง์ง ์์ ๊ธฐ๊ฐ์ ๋ช ์ด์ธ์ง๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํ์ธ์.
2. ์ ํ์ฌํญ
- prices์ ๊ฐ ๊ฐ๊ฒฉ์ 1 ์ด์ 10,000 ์ดํ์ธ ์์ฐ์์ ๋๋ค.
- prices์ ๊ธธ์ด๋ 2 ์ด์ 100,000 ์ดํ์ ๋๋ค.
![](https://blog.kakaocdn.net/dn/d6R73G/btrWLwVkR6U/IFkadklPC5ph48iz5DB8j0/img.png)
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