File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ var MinStack = function ( ) {
3
+ this . _top = - 1 ;
4
+ this . data = [ ] ;
5
+ this . min = Number . MAX_SAFE_INTEGER ;
6
+ } ;
7
+
8
+ /**
9
+ * @param {number } val
10
+ * @return {void }
11
+ */
12
+ MinStack . prototype . push = function ( val ) {
13
+ this . data [ ++ this . _top ] = this . min ;
14
+ this . data [ ++ this . _top ] = val ;
15
+ val < this . min && ( this . min = val ) ;
16
+ } ;
17
+
18
+ /**
19
+ * @return {void }
20
+ */
21
+ MinStack . prototype . pop = function ( ) {
22
+ this . min = this . data [ -- this . _top ] ;
23
+ -- this . _top ;
24
+ } ;
25
+
26
+ /**
27
+ * @return {number }
28
+ */
29
+ MinStack . prototype . top = function ( ) {
30
+ return this . data [ this . _top ] ;
31
+ } ;
32
+
33
+ /**
34
+ * @return {number }
35
+ */
36
+ MinStack . prototype . getMin = function ( ) {
37
+ return this . min ;
38
+ } ;
39
+
40
+ /**
41
+ * Your MinStack object will be instantiated and called as such:
42
+ * var obj = new MinStack()
43
+ * obj.push(val)
44
+ * obj.pop()
45
+ * var param_3 = obj.top()
46
+ * var param_4 = obj.getMin()
47
+ */
You can’t perform that action at this time.
0 commit comments