We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1b8631f commit ad4b75aCopy full SHA for ad4b75a
solution/1019.Next Greater Node In Linked List/Solution.java
@@ -0,0 +1,18 @@
1
+class Solution {
2
+ public int[] nextLargerNodes(ListNode head) {
3
+ List<Integer> list = new ArrayList<>();
4
+ while (head != null) {
5
+ list.add(head.val);
6
+ head = head.next;
7
+ }
8
+ int[] res = new int[list.size()];
9
+ Deque<Integer> stack = new ArrayDeque<>();
10
+ for (int i = 0; i < list.size(); ++i) {
11
+ while (!stack.isEmpty() && list.get(i) > list.get(stack.peek())) {
12
+ res[stack.pop()] = list.get(i);
13
14
+ stack.push(i);
15
16
+ return res;
17
18
+}
0 commit comments