Skip to content
the poor coder

Leetcode - Daily Temperatures Solution

Poor Man
Published
Updated
Reading time
1 min read

Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.

For example, given the list of temperatures T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be [1, 1, 4, 2, 1, 1, 0, 0].

Note: The length of temperatures will be in the range [1, 30000]. Each temperature will be an integer in the range [30, 100].

Solution in Python#

Python
class Solution:
    def dailyTemperatures(self, T: List[int]) -> List[int]:
        output = [0]*len(T)
        warmer = [300002]*102
        for index,value in reversed(list(enumerate(T))):
            nearest_warmer = min(warmer[i] for i in range(value+1,102))
            if nearest_warmer != 300002:
                output[index] = nearest_warmer-index
            warmer[value] = index
        return output

Keep going

2021

Leetcode - Crawler Log Folder Solution

The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: "../" : Move to the parent folder of the current folder. (If you are already in the main…

leetcodestack1 min read
2021

Leetcode - Make The String Great Solution

Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: 0 <= i <= s.length - 2 s[i] is a lower-case letter and s[i + 1] is…

ESC