码迷,mamicode.com
首页 > 编程语言 > 详细

LeetCode-155 Min Stack Solution (with Java)

时间:2020-03-02 14:56:29      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:struct   desc   epc   ons   int   img   png   col   ram   

1. Description: 技术图片

2. Examples:

技术图片

3.Solutions:

 1 /**
 2  * Created by sheepcore on 2019-05-07
 3  * Your MinStack object will be instantiated and called as such:
 4  * MinStack obj = new MinStack();
 5  * obj.push(x);
 6  * obj.pop();
 7  * int param_3 = obj.top();
 8  * int param_4 = obj.getMin();
 9  */
10 class MinStack {
11     /** initialize your data structure here. */
12      private Stack<Integer> stack;
13 
14     public MinStack(){
15         stack = new Stack<Integer>();
16     }
17     public int getMin(){
18         int min = Integer.MAX_VALUE;
19         for(Integer integer : stack){
20             if(integer < min)
21                 min = integer;
22         }
23         return min;
24     }
25     public void push(int x){
26         stack.push(x);
27     }
28 
29     public int top(){
30         return stack.peek();
31     }
32 
33     public int pop(){
34         return stack.pop();
35     }
36 }

 

LeetCode-155 Min Stack Solution (with Java)

标签:struct   desc   epc   ons   int   img   png   col   ram   

原文地址:https://www.cnblogs.com/sheepcore/p/12395243.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!