- Leetcode 1019. Next Greater Node
- [LeetCode] Next Greater Node In
- Leetcode 1019 Next Greater Node
- LeetCode #1019 Next Greater Node
- 496. Next Greater Element I
- leetcode503. Next Greater Elemen
- [刷题防痴呆] 0496 - 下一个更大的元素 I (Next
- [刷题防痴呆] 0503 - 下一个更大的元素 II (Next
- Leetcode 503 - Next Greater Elem
- Leetcode #496 Next Greater Eleme
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
Next Greater Node In Linked List2. Solution
解析:Version 1,这个题跟Leetcode 503. Next Greater Element II
非常相似,只不过是把数组换成了链表,参考https://blog.csdn.net/Quincuntial/article/details/118733487即可。
- Version 1
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def nextLargerNodes(self, head: ListNode) -> List[int]:
result = []
nums = []
node = head
index = 0
stack = []
while node:
while stack and nums[stack[-1]] < node.val:
result[stack.pop()] = node.val
nums.append(node.val)
result.append(0)
stack.append(index)
node = node.next
index += 1
return result
网友评论