Python代码:
def nextGreaterElement(self, findNums, nums):
"""
:type findNums: List[int]
:type nums: List[int]
:rtype: List[int]
"""
st = []
dic = {}
for num in nums:
while len(st) and st[-1]<num:
dic[st.pop()] = num
st.append(num)
return [dic.get(x,-1) for x in findNums]
版权声明:本文为weixin_45361800原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。