Closed utterances-bot closed 2 weeks ago
위쪽 코드에서 list
-> deque
로만 바꿔줘도 효율성 통과됩니다!
from collections import deque
def solution(prices):
ret = []
q = deque(prices)
while len(q) > 0:
cur_price = q.popleft()
s = 0
for p in q:
s += 1
if cur_price > p:
break
ret.append(s)
return ret
@changwoomon
오... 찾아보니 deque
는 내부적으로 이중 링크드 리스트로 구현되어있다고 하네요. 이로 인해서 popleft
같은 메소드도 O(1) 의 시간복잡도로 빠르게 작동하나봅니다.
좋은 인사이트 얻고가요 감사합니다!
[PS #09] 주식가격 (42584)
https://hudi.blog/programmers-42584/