Created
October 22, 2020 09:28
-
-
Save inspirit941/d63e672a63e03ce340d2e5226578d751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def dailyTemperatures(self, T: List[int]) -> List[int]: | |
# 현재 온도를 stack에 저장. | |
# 다음날 온도가 현재보다 높으면 stack 값을 꺼내서, 날씨차이 저장. | |
# 낮으면 스택 값은 계속 유지됨. | |
stack = [] | |
answer = [0 for _ in range(len(T))] | |
for idx, value in enumerate(T): | |
while stack and value > T[stack[-1]]: | |
last = stack.pop() | |
answer[last] = idx - last | |
stack.append(idx) | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment