标签:stack turn node self end nbsp sel next class
单调栈的应用.
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
标签:stack turn node self end nbsp sel next class
原文地址:https://www.cnblogs.com/zywscq/p/10739575.html