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;
    }
}

 

posted on 2022-04-20 13:24  阳光明媚的菲越  阅读(14)  评论(0编辑  收藏  举报