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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-25外企也半夜发布上线吗?
- 2024-05-24鸿蒙原生应用再新丁!芒果TV 入局鸿蒙
- 2024-05-22基本概念
- 2024-05-22检索数据
- 2024-05-22排序数据
- 2024-05-22基础过滤数据
- 2024-05-22通过逻辑操作符过滤数据
- 2024-05-22通过通配符过滤数据
- 2024-05-22字段的拼接与计算
- 2024-05-22聚合函数