- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1019.java
40 lines (36 loc) · 1.06 KB
/
_1019.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
packagecom.fishercoder.solutions.secondthousand;
importcom.fishercoder.common.classes.ListNode;
publicclass_1019 {
publicstaticclassSolution1 {
publicint[] nextLargerNodes(ListNodehead) {
intlen = findLength(head);
int[] result = newint[len];
ListNodetmp = head;
inti = 0;
while (tmp != null) {
result[i++] = findNextLarger(tmp.val, tmp);
tmp = tmp.next;
}
returnresult;
}
privateintfindNextLarger(intval, ListNodehead) {
ListNodetmp = head.next;
while (tmp != null) {
if (tmp.val > val) {
returntmp.val;
}
tmp = tmp.next;
}
return0;
}
privateintfindLength(ListNodehead) {
ListNodetmp = head;
intcount = 0;
while (tmp != null) {
tmp = tmp.next;
count++;
}
returncount;
}
}
}