首页 > 其他 > 详细

Leetcode 496. Next Greater Element I

时间:2019-04-20 10:07:36      阅读:151      评论:0      收藏:0      [点我收藏+]

单调栈的应用.

class Solution:
    def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
        next = []
        stack = []
        for i in range(len(nums2)):
            while stack and stack[-1][1] < nums2[i]:
                next[stack.pop()[0]] = nums2[i]
            stack.append((i, nums2[i]))
            next.append(-1)
        ret = []
        for val in nums1:
            ret.append(next[nums2.index(val)])
        return ret

 

Leetcode 496. Next Greater Element I

原文:https://www.cnblogs.com/zywscq/p/10739648.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!