1019. Next Greater Node In Linked List

2022/4/20 14:42:37

本文主要是介绍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;
    }
}

 



这篇关于1019. Next Greater Node In Linked List的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程