class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
st =[0]
result = [0]*len(temperatures)
if len(result)<=1:
return result
for i in range(1,len(temperatures)):
if temperatures[i] <= temperatures[st[-1]]:
st.append(i)
else:
while st != [] and temperatures[i] > temperatures[st[-1]]:
result[st[-1]]=i-st[-1]
st.pop()
st.append(i)
return result
class Solution:
def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
_map = {}
result=[]
st=[0]
for i in range(1,len(nums2)):
if nums2[i] <= nums2[st[-1]]:
st.append(i)
else:
while st!=[] and nums2[i]> nums2[st[-1]]:
if nums2[st[-1]] in nums1:
_map[nums2[st[-1]]]= nums2[i]
st.pop()
st.append(i)
for i in nums1:
result.append(_map.get(i,-1))
return result