classMinStack{privateStack<Integer> stack;privateStack<Integer> helper;// 思路,维护一个最小栈helper,对应当前子栈的最小值/** initialize your data structure here. */publicMinStack(){stack =newStack<>();helper =newStack<>();}publicvoidpush(int val){stack.push(val);if(helper.empty()){helper.push(val);}else{helper.push(val > helper.peek()? helper.peek(): val);}}publicvoidpop(){stack.pop();helper.pop();}publicinttop(){return stack.peek();}publicintgetMin(){return helper.peek();}}/*** Your MinStack object will be instantiated and called as such:* MinStack obj = new MinStack();* obj.push(val);* obj.pop();* int param_3 = obj.top();* int param_4 = obj.getMin();*/
更新版
换成 ArrayDeque,效率更高了
classMinStack{Deque<Integer> stack;Deque<Integer> minStack;/** initialize your data structure here. */publicMinStack(){stack =newArrayDeque<>();minStack =newArrayDeque<>();}publicvoidpush(int val){stack.push(val);int min = minStack.isEmpty()? val : minStack.peek();val = val < min ? val : min;minStack.push(val);}publicvoidpop(){stack.pop();minStack.pop();}publicinttop(){return stack.peek();}publicintgetMin(){return minStack.peek();}}
文章目录题目描述代码 & 思路更新版题目描述
感觉和合并二叉树类似,都是很好进行递归的问题
代码 & 思路
翻转当前结点的左、右结点对当前结点的左、右结点进行翻转函数【自底向上】
/*** Definition for a binary tree node.* public class TreeNode …
问题描述
在本地主机开了个FTP服务器,本机可以正常访问,但是外部主机不能访问FTP服务器
解决方法
① 一开始以为是服务端Xlight FTP的问题,检查权限并没有发现问题 ② 接着考虑到有没有可能是客户端Flash FXP的问题,于是尝试直…