1019. Next Greater Node In Linked List (Medium) - TengnanYao/daily_leetcode GitHub Wiki
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def nextLargerNodes(self, head):
"""
:type head: ListNode
:rtype: List[int]
"""
result, stack = [], []
while head:
val = head.val
while stack and val > stack[-1][1]:
result[stack.pop()[0]] = val
stack.append((len(result), val))
result.append(0)
head = head.next
return result