@@ -0,0 +1,1008 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Stack;%0A%0A/**%0A * https://leetcode.com/problems/next-greater-node-in-linked-list/%0A */%0Apublic class Problem1019 %7B%0A    public static class ListNode %7B%0A        int val;%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public int%5B%5D nextLargerNodes(ListNode head) %7B%0A        List%3CInteger%3E list = new ArrayList%3C%3E();%0A        for (ListNode n = head; n != null; n = n.next) %7B%0A            list.add(n.val);%0A        %7D%0A        int%5B%5D answer = new int%5Blist.size()%5D;%0A        Stack%3CInteger%3E stack = new Stack%3C%3E();%0A        for (int i = list.size() - 1; i %3E= 0; i--) %7B%0A            while (!stack.isEmpty() && stack.peek() %3C= list.get(i)) %7B%0A                stack.pop();%0A            %7D%0A            if (stack.isEmpty()) %7B%0A                answer%5Bi%5D = 0;%0A            %7D else %7B%0A                answer%5Bi%5D = stack.peek();%0A            %7D%0A            stack.add(list.get(i));%0A        %7D%0A        return answer;%0A    %7D%0A%7D%0A

Solve problem 1019