본문 바로가기
python-algorithm

leetcode 739. Daily Temperatures

by 무적김두칠 2023. 2. 23.

https://leetcode.com/problems/daily-temperatures/description/

 

Daily Temperatures - LeetCode

Can you solve this real interview question? Daily Temperatures - Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
        answer = [0* len(temperatures)
        stack = []
        for i, cur in enumerate(temperatures):
            while stack and cur > temperatures[stack[-1]]:
                last = stack.pop()
                answer [last] = i -last
            stack.append(i)
 
        return answer
cs
반응형

'python-algorithm' 카테고리의 다른 글

백준 27541 末尾の文字 (Last Letter)  (0) 2023.02.24
leetcode 232. Implement Queue using Stacks  (0) 2023.02.23
leetcode 316. Remove Duplicate Letters  (1) 2023.02.23
leetcode 20. Valid Parentheses  (0) 2023.02.23
백준 9773 ID Key  (0) 2023.02.21

댓글