Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1019 - Next Greater Node In Linked List.

    Medium

    You are given the head of a linked list with n nodes.

    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.

    Return an integer array answer where answer[i] is the value of the next greater node of the <code>i<sup>th</sup></code> node ( 1-indexed ). If the <code>i<sup>th</sup></code> node does not have a next greater node, set answer[i] = 0.

    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

    Constraints:

    • The number of nodes in the list is n.

    • <code>1 <= n <= 10<sup>4</sup></code>

    • <code>1 <= Node.val <= 10<sup>9</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final IntArray nextLargerNodes(ListNode head)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait