[LeetCode][Python3] 739. Daily Temperatures
2019. 9. 12. 00:57 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/daily-temperatures/
My Solution :
class Solution:
def dailyTemperatures(self, T):
ans = [0]*len(T)
INF = float('INF')
min_idx_t = [INF]*102
for i in range(len(T)-1, -1, -1):
t = T[i]
min_idx_t[t] = i
min_idx = min(min_idx_t[t+1:])
if min_idx is not INF:
ans[i] = min_idx-i
return ans
My Solution2 :
class Solution:
def dailyTemperatures(self, T):
ans = [0]*len(T)
stack = []
for i, t in enumerate(T):
while stack and T[stack[-1]] < t:
idx = stack.pop()
ans[idx] = i - idx
stack.append(i)
return ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 647. Palindromic Substrings (1) | 2019.09.25 |
---|---|
[LeetCode][Python3] 338. Counting Bits (0) | 2019.09.24 |
[LeetCode][Python3] 406. Queue Reconstruction by Height (0) | 2019.09.23 |
[LeetCode][Python3] 90. Subsets II (0) | 2019.09.17 |
[LeetCode][Python3] 401. Binary Watch (0) | 2019.09.05 |
[LeetCode][Python3] 692. Top K Frequent Words (0) | 2019.09.03 |
[LeetCode][Python3] 89. Gray Code (0) | 2019.09.03 |
[LeetCode][Python3] 357. Count Numbers with Unique Digits (0) | 2019.08.29 |
최근에 달린 댓글 최근에 달린 댓글