1019. Next Greater Node In Linked List Medium
1/**
2 * [1019] Next Greater Node In Linked List
3 *
4 * You are given the head of a linked list with n nodes.
5 * For each node in the list, find the value of the next greater node. That is, for each node, find the value of the first node that is next to it and has a strictly larger value than it.
6 * Return an integer array answer where answer[i] is the value of the next greater node of the i^th node (1-indexed). If the i^th node does not have a next greater node, set answer[i] = 0.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/08/05/linkedlistnext1.jpg" style="width: 304px; height: 133px;" />
10 * Input: head = [2,1,5]
11 * Output: [5,5,0]
12 *
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/08/05/linkedlistnext2.jpg" style="width: 500px; height: 113px;" />
15 * Input: head = [2,7,4,3,5]
16 * Output: [7,0,5,5,0]
17 *
18 *
19 * Constraints:
20 *
21 * The number of nodes in the list is n.
22 * 1 <= n <= 10^4
23 * 1 <= Node.val <= 10^9
24 *
25 */
26pub struct Solution {}
27use crate::util::linked_list::{ListNode, to_list};
28
29// problem: https://leetcode.com/problems/next-greater-node-in-linked-list/
30// discuss: https://leetcode.com/problems/next-greater-node-in-linked-list/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34// Definition for singly-linked list.
35// #[derive(PartialEq, Eq, Clone, Debug)]
36// pub struct ListNode {
37// pub val: i32,
38// pub next: Option<Box<ListNode>>
39// }
40//
41// impl ListNode {
42// #[inline]
43// fn new(val: i32) -> Self {
44// ListNode {
45// next: None,
46// val
47// }
48// }
49// }
50impl Solution {
51 pub fn next_larger_nodes(head: Option<Box<ListNode>>) -> Vec<i32> {
52 vec![]
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_1019() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.