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