Next Greater Node In Linked List LeetCode solution in Java

1
class Solution {
2
public int[] nextLargerNodes(ListNode head) {
3
ListNode length = head;
4
int l = 0;
5
while (length != null) {
6
length = length.next;
7
l++;
8
}
9
int[] res = new int[l];
10
int i = 0;
11
ListNode temp = head;
12

13
while (temp != null) {
14
ListNode temp1 = temp.next;
15
int max = temp.val;
16

17
while (temp1 != null) {
18
if (temp1.val > max) {
19
max = temp1.val;
20
res[i] = max;
21
break;
22
}
23

24
temp1 = temp1.next;
25
}
26
temp = temp.next;
27
i++;
28
}
29
return res;
30
}
31
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0