国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

MinStack

2019-11-14 22:01:34
字體:
來源:轉載
供稿:網友
MinStack

leetcode Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.getMin() -- Retrieve the minimum element in the stack.

class MinStack {    PRivate Stack<Integer> stack;    private Stack<Integer> min;  //存儲最小數的棧    public MinStack() {        stack = new Stack<Integer>();        min = new Stack<Integer>();    }    public void push(int x) {                if (min.isEmpty() || min.peek()>=x)            min.push(x);        stack.push(x);    }    public void pop() {        if (stack.peek().equals(min.peek()))            min.pop();        stack.pop();    }    public int top() {        return stack.peek();    }    public int getMin() {        return min.peek();    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永登县| 新源县| 宜兰县| 丹棱县| 英吉沙县| 金塔县| 札达县| 墨江| 双牌县| 贵德县| 丹棱县| 绵竹市| 甘洛县| 雷波县| 浮梁县| 泰和县| 张家港市| 郯城县| 灌云县| 天峨县| 锡林浩特市| 珲春市| 郎溪县| 稷山县| 桃源县| 中阳县| 建德市| 孙吴县| 遂平县| 越西县| 江津市| 泸州市| 云梦县| 郯城县| 黄骅市| 永宁县| 乡宁县| 建阳市| 泸溪县| 镇宁| 丰城市|