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();}}
请教:我的grub.cfg里面的内容如下,请教怎样改代码才能让WIN7设为默认启动发布时间:2011-09-24 15:43:24来源:红联作者:baiguanglin## DO NOT EDIT THIS FILE## It is automatically generated by grub-mkconfig using templates# from /etc/grub.d and s…
文章目录题目描述代码 & 思路更新版题目描述
感觉和合并二叉树类似,都是很好进行递归的问题
代码 & 思路
翻转当前结点的左、右结点对当前结点的左、右结点进行翻转函数【自底向上】
/*** Definition for a binary tree node.* public class TreeNode …
C 中随机函数random函数的使用方法一、random函数不是ANSI C标准,不能在gcc,vc等编译器下编译通过。 可改用C下的rand函数来实现。1、C标准函数库提供一随机数生成器rand,返回0-RAND_MAX之间均匀分布的伪随机整数。 RAND_MAX必须至少为32767。…
课程概况This specialization is designed to let you explore computational thinking and beginning C programming topics, applying those concepts to develop solutions to a variety of practical problems.The first course assumes no programming experience, and th…