栈-leetcode 496. Next Greater Element I
来源:互联网 发布:上海巨人网络校园招聘 编辑:程序博客网 时间:2024/06/08 00:57
原题链接:Next Greater Element I
题解:
public class Solution { public int[] nextGreaterElement(int[] findNums, int[] nums) { /* Time Complexity:O(N) Space Complexity:O(N) */ if(nums==null || nums.length==0)return new int[]{}; HashMap<Integer,Integer>map=new HashMap<>(); ArrayDeque<Integer>sta=new ArrayDeque<>(); for(int num:nums){ while(!sta.isEmpty() && sta.peek()<num){ map.put(sta.pop(),num); } sta.push(num); } int[] res=new int[findNums.length]; for(int i=0;i<findNums.length;i++){ res[i]=map.getOrDefault(findNums[i],-1); } return res; }}
阅读全文
0 0
- leetcode -- 496. Next Greater Element I 【栈】
- 栈-leetcode 496. Next Greater Element I
- 【Leetcode】496. Next Greater Element I
- 【LeetCode】496. Next Greater Element I
- LeetCode 496. Next Greater Element I
- LeetCode 496. Next Greater Element I
- leetcode 496. Next Greater Element I
- LeetCode-496. Next Greater Element I
- [LeetCode]496. Next Greater Element I
- LeetCode 496. Next Greater Element I
- LeetCode 496. Next Greater Element I
- LeetCode | 496. Next Greater Element I
- 【LeetCode】496. Next Greater Element I
- 【LeetCode】496. Next Greater Element I
- Leetcode 496. Next Greater Element I
- LeetCode:496. Next Greater Element I
- LeetCode OJ 496. Next Greater Element I
- 【C++】【LeetCode】496. Next Greater Element I
- 如何备份SolidWorks网络版服务器
- codeforces 682C Alyona and the Tree
- equals重写
- QFileSystemWatcher使用整理
- nginx报错:nginx.service failed to run 'start-pre' task: No space left on device
- 栈-leetcode 496. Next Greater Element I
- (python)百练1000: A+B Problem
- SSM框架中,mybits.xml配置,映射器的注意点
- 【前端】Handlebars,requirejs使用入门
- 历史图纸导入PDM方案
- Maven整合SSM三大框架
- 简单的春鞋!
- 马云无人超市店开业了,让我们一起去体验购物的乐趣
- CSDN博客自定义栏目