题目:
解答:
class Solution:
def nextGreaterElements(self, nums: List[int]) -> List[int]:
stk = nums[::-1]
ans = [-1 for _ in range(len(nums))]
sz = len(nums) - 1
for ind, num in enumerate(nums[::-1]):
while stk and stk[-1] <= num:
stk.pop()
ans[sz - ind] = -1 if not stk else stk[-1]
stk.append(num)
return ans
来源:CSDN
作者:sinat_15355869
链接:https://blog.csdn.net/sinat_15355869/article/details/103777135