LeetCode-739
Daily Temperature : ๋ช ์ผ ํ ๊ธฐ์จ์ด ์ค๋ฅผ๊น?
note : Answer
:::python
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
out = []
left, right = 0, 0
while left != len(temperatures)-1:
day = 0
check = 0
while right < len(temperatures):
if (temperatures[left] < temperatures[right]):
out.append(day)
check = 1
right = left + 1
break
right+=1
day+=1
if check==0:
out.append(0)
right = left + 1
left+=1
out.append(0)
return out
Result : Timeoutms Memory: Timeoutmb
Answer
:::python
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
Result : 1352ms Memory: 28.6mb
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[leetcode-232] Implement Queue using Stacks (0) | 2023.04.06 |
---|---|
[leetcode-225] Implement Queue using Stacks (0) | 2023.04.05 |
[LeetCode-316] Remove Duplicate Letters (0) | 2023.03.30 |
[leetcode-20] Valid Parenthese (0) | 2023.03.29 |
[leetcode 92] Reverse Linked List II (0) | 2023.03.26 |