![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
栈和队列
qch60925
这个作者很懒,什么都没留下…
展开
-
946-判断b数组是否为a入栈后的弹出顺序
构造辅助栈 将a数组的元素入栈。如果遇到b数组的数。就把他pop,判断最后a数组全入栈了,栈是否为空 Stack<Integer> st = new Stack<>(); int j=0; //把pushed元素入栈,如果与出栈元素相同,就pop出去 for(int i:pushed){ st.push(i); while(!st.isEmpty()&&st.pe原创 2021-03-16 20:52:38 · 73 阅读 · 0 评论 -
155-最小元素的栈
最小栈 public class MinStack { Stack <Integer> st; Stack <Integer> minStack; /** initialize your data structure here. */ public MinStack() { st = new Stack<>(); minStack = new Stack<>(); } public原创 2021-03-16 20:49:44 · 67 阅读 · 0 评论 -
933-最近的请求次数
933-最近的请求次数 题目要求: 输入: [“RecentCounter”, “ping”, “ping”, “ping”, “ping”] [[], [1], [100], [3001], [3002]] 输出: [null, 1, 2, 3, 3] 第一次做队列的题目, ## while嵌套if判断那么时间会超时 class RecentCounter { Queue<Integer> que; //初始化计数器 public RecentCounter() {原创 2021-02-08 20:43:44 · 101 阅读 · 0 评论 -
20-有效地括号
20-有效地括号 解法1:利用堆栈,每一个符号与堆栈的top作判断; class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<>(); for(int i=0;i<s.length();i++){ char ch=s.charAt(i); if(ch=='('||ch=='{原创 2021-02-07 22:11:07 · 69 阅读 · 0 评论 -
1544-删除相邻的大小写字母
删除相邻的大小写字母; 使用栈消除 stringBuilder实现反转等操作 class Solution { public String makeGood(String s) { Stack<Character> stack=new Stack<>(); for(int i=0;i<s.length();i++){ if(!stack.isEmpty()&&Math.abs(s.charAt(i)原创 2021-02-06 00:38:32 · 288 阅读 · 0 评论 -
225-队列实现栈232-栈实现队列;
225-队列实现栈 用两个队列进行模拟 push:将新push的元素送入B队列中; 交换AB队列,在A队列进行余下操作; class MyStack { Queue<Integer> a; Queue<Integer> b; public MyStack() { a=new LinkedList<>(); b=new LinkedList<>(); } public void pus原创 2021-02-04 19:08:49 · 43 阅读 · 0 评论