def solution(prices):
size = len(prices)
answer = [0] * size
for i in range(size):
for j in range(i + 1, size):
if prices[i] <= prices[j]: answer[i] += 1
else:
answer[i] += 1
break
return answer
1. ์ฃผ์ ๊ฐ๊ฒฉ์ ์์๋ ์คํ๊ณผ ์์น์ธ๊ฐ ์ผ๋ง๋ ์ค๋ ์ง์๋์๋์ง์ ๋ํด ๊ธฐ๋ก์ ๋จ๊ธธ ๋ฐฐ์ด์ ์์ฑ
def solution(prices):
stack = []
answer = [0] * len(prices)
2. ๊ฐ ๊ธ์ก์ ์ ๋ณด๋ฅผ for๋ฌธ์ผ๋ก ์ํํ๋ฉด์ ์์น์ธ ์ฌ๋ถ๋ฅผ ํ์ธ
for i in range(len(prices)):
while stack and prices[stack[-1]] > prices[i]:
past = stsack.pop()
answer[past] = i - past
stack.append(i)
3. ๋จ์ ์คํ์ ์ ๋ถ ๋น์ฐ๊ณ , ์ ๋ต์ ๋ฐํ
for i in stack:
answer[i] = len(prices) - 1 - i
return answer
def solution(prices):
stack = []
answer = [0] * len(prices)
for i in range(len(prices)):
while stack and prices[stack[-1]] > prices[i]:
past = stsack.pop()
answer[past] = i - past
stack.append(i)
for i in stack:
answer[i] = len(prices) - 1 - i
return answer