다른 분들 파이썬 코드를 보면 조건문을 쓰셨거나, O(N2)인데도 통과되셨다는 분이 계셔서..
뭐가 문제인지 모르겠네요.
첫 번째 코드>
def solution(prices):
answer = []
for idx in range(len(prices)):
for j, compare in enumerate(prices[idx+1:]):
if prices[idx] > compare:
break
answer.append(j+1 if not idx == len(prices)-1 else 0)
return answer
두 번째 코드 (최적화 시도)>
def solution(prices):
answer = [0] * len(prices)
for idx in range(len(prices)):
for compare in prices[idx+1:]:
if prices[idx] <= compare:
answer[idx] += 1
elif prices[idx] > compare:
answer[idx] += 1
break