This problem is as same as https://www.cnblogs.com/feiflytech/p/16169025.html
class Solution { public int[] nextLargerNodes(ListNode head) { List<Integer> list = new ArrayList<>(); ListNode point = head; while(point!=null) { list.add(point.val); point = point.next; } Stack<Integer> stk = new Stack<>(); int[] res = new int[list.size()]; for(int i=0;i<list.size();i++){ while(!stk.isEmpty()&&list.get(i)>list.get(stk.peek())){ res[stk.pop()]=list.get(i); } stk.push(i); } return res; } }