From e6d5ae7fc9c67dd8d952b7aa005684967b3c1adb Mon Sep 17 00:00:00 2001 From: Qiming Xu <458173774@qq.com> Date: Thu, 28 Dec 2023 00:30:23 +0000 Subject: [PATCH] leetcode: finished #1019 --- content/leetcode/2023/12.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/content/leetcode/2023/12.md b/content/leetcode/2023/12.md index 6eb95c80..f2679acd 100644 --- a/content/leetcode/2023/12.md +++ b/content/leetcode/2023/12.md @@ -3,6 +3,38 @@ title: 2023.12 draft: false --- +# 2023.12.28 + +```python +# +# @lc app=leetcode.cn id=1019 lang=python3 +# +# [1019] 链表中的下一个更大节点 +# + + +# @lc code=start +# 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: Optional[ListNode]) -> List[int]: + stack = [] + res = [] + while head: + while stack and stack[-1][1] < head.val: + res[stack.pop()[0]] = head.val + stack.append((len(res), head.val)) + res.append(0) + head = head.next + return res + + +# @lc code=end +``` + # 2023.12.27 ```python