Next Greater Node In Linked List LeetCode solution in Java
1class Solution {2public int[] nextLargerNodes(ListNode head) {3ListNode length = head;4int l = 0;5while (length != null) {6length = length.next;7l++;8}9int[] res = new int[l];10int i = 0;11ListNode temp = head;1213while (temp != null) {14ListNode temp1 = temp.next;15int max = temp.val;1617while (temp1 != null) {18if (temp1.val > max) {19max = temp1.val;20res[i] = max;21break;22}2324temp1 = temp1.next;25}26temp = temp.next;27i++;28}29return res;30}31}