#1019
Next Greater Node In Linked List
specialist · 650 · lc medium +30 · verified · 63.9% accepted · 3,527 likes · top 67%
Description
Given the head of a linked list with n nodes, for each node find the value of the first subsequent node with a strictly greater value.
Return an integer array answer where answer[i] is the next greater value for the ith node (1-indexed), or 0 if no such node exists.
Example 1:
Input: head = [2,1,5]
Output: [5,5,0]
Example 2:
Input: head = [2,7,4,3,5]
Output: [7,0,5,5,0]
Code
1
2
3
4
5
6
7
8