编程语言
首页 > 编程语言> > 1019. Next Greater Node In Linked List

1019. Next Greater Node In Linked List

作者:互联网

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

 

标签:Node,Greater,point,int,list,List,stk,res,new
来源: https://www.cnblogs.com/feiflytech/p/16169459.html