首页 > 其他 > 详细

Leetcode 1019. Next Greater Node In Linked List

时间:2019-04-20 00:37:59      阅读:177      评论:0      收藏:0      [点我收藏+]

单调栈的应用.

class Solution:
    def nextLargerNodes(self, head: ListNode) -> List[int]:
        stack = []
        ret = []
        while head:
            while stack and stack[-1][1] < head.val:
                ret[stack.pop()[0]] = head.val
            stack.append((len(ret), head.val))
            ret.append(0)
            head = head.next
        return ret

 

Leetcode 1019. Next Greater Node In Linked List

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

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