1、下一个更大元素 I
class Solution:
def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
stackIn = []
dictIn = {}
# 对第二个数组遍历,如果新元素小于栈顶元素,入栈;
# 否则存入dict中, 然后弹出栈顶,此外还要对比栈中剩余元素。
# 另外要将新元素存入栈顶。
for i in nums2:
if stackIn:
while stackIn:
l = stackIn[-1]
if l
关注
打赏