<LeetCode 문제>
https://leetcode.com/problems/daily-temperatures/
Daily Temperatures - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
매일의 화씨 온도 리스트 T를 입력받아서, 더 따뜻한 날씨를 위해서는 며칠을 더 기다려야 하는지를 출력하는 문제입니다.
<풀이>
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
ans=[0]*len(temperatures)
stack=[] #stack 선언
for i,cur in enumerate(temperatures):
while stack and cur >temperatures[stack[-1]]:
last = stack.pop()
ans[last] = i-last
stack.append(i)
return ans
<학습내용>
1.
<학습이 필요한 내용>
1.
'Algorithm > 파이썬 알고리즘 인터뷰 스터디' 카테고리의 다른 글
| [스택, 큐] 24 스택을 이용한 큐 구현(Implement Queue using Stacks) - 작성중 (0) | 2021.08.16 |
|---|---|
| [스택, 큐] 23 큐를 이용한 스택 구현(Implement Stack using Queues) - 작성중 (0) | 2021.08.16 |
| [스택, 큐] 21 중복 문자 제거(Remove Duplicate Letters) - 작성중 (0) | 2021.08.16 |
| [스택, 큐] 20 유효한 괄호(Valid Parentheses) (0) | 2021.08.10 |
| [연결리스트] 19 역순 연결 리스트 II(Reverse Linked List II) (0) | 2021.08.09 |