Leetcode 1019. Next Greater Node In Linked List

Posted 周洋的Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 1019. Next Greater Node In Linked List相关的知识,希望对你有一定的参考价值。

单调栈的应用.

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的主要内容,如果未能解决你的问题,请参考以下文章

[栈] leetcode 1019 Next Greater Node In Linked List

Leetcode 1019. Next Greater Node In Linked List

Leetcode 1019. Next Greater Node In Linked List

[LeetCode] 1019. Next Greater Node In Linked List

LeetCode 1019. Next Greater Node In Linked List (链表中的下一个更大节点)

Leetcode 87. Scramble String