File tree 3 files changed +83
-1
lines changed
3 files changed +83
-1
lines changed Original file line number Diff line number Diff line change 88
88
| [ 125] [ 125-question ] | [ Valid Palindrome] [ 125-tips ] | [ Easy] [ E ] | | [ ✅] [ 125-js ] | [ ✅] [ 125-kotlin ] |
89
89
| [ 136] [ 136-question ] | [ Single Number] [ 136-tips ] | [ Easy] [ E ] | | [ ✅] [ 136-js ] | [ ✅] [ 136-kotlin ] |
90
90
| [ 141] [ 141-question ] | [ Linked List Cycle] [ 141-tips ] | [ Easy] [ E ] | [ ✅] [ 141-java ] | | - |
91
- | [ 155] [ 155-question ] | [ Min Stack] [ 155-tips ] | [ Easy] [ E ] | [ ✅] [ 155-java ] | | [ ✅] [ 155-kotlin ] |
91
+ | [ 155] [ 155-question ] | [ Min Stack] [ 155-tips ] | [ Easy] [ E ] | [ ✅] [ 155-java ] | [ ✅ ] [ 155-js ] | [ ✅] [ 155-kotlin ] |
92
92
| [ 160] [ 160-question ] | [ Intersection of Two Linked Lists] [ 160-tips ] | [ Easy] [ E ] | [ ✅] [ 160-java ] | | - |
93
93
| [ 226] [ 226-question ] | [ Invert Binary Tree] [ 226-tips ] | [ Easy] [ E ] | [ ✅] [ 226-java ] | [ ✅] [ 226-js ] | [ ✅] [ 226-kotlin ] |
94
94
| [ 504] [ 504-question ] | [ Base 7] [ 504-tips ] | [ Easy] [ E ] | | | [ ✅] [ 504-kotlin ] |
@@ -467,6 +467,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
467
467
[ 122-js ] : ./src/_122/Solution.js
468
468
[ 125-js ] : ./src/_125/Solution.js
469
469
[ 136-js ] : ./src/_136/Solution.js
470
+ [ 155-js ] : ./src/_155/Solution.js
470
471
[ 226-js ] : ./src/_226/Solution.js
471
472
[ 561-js ] : ./src/_561/Solution.js
472
473
[ 643-js ] : ./src/_643/Solution.js
Original file line number Diff line number Diff line change
1
+ var MinStack = function ( ) {
2
+ this . stack = [ ]
3
+ } ;
4
+
5
+ /**
6
+ * @param {number } x
7
+ * @return {void }
8
+ */
9
+ MinStack . prototype . push = function ( x ) {
10
+ let min = this . stack . length === 0 ? x : this . stack [ this . stack . length - 1 ] . min
11
+ this . stack . push ( { val : x , min : Math . min ( min , x ) } )
12
+ } ;
13
+
14
+ /**
15
+ * @return {void }
16
+ */
17
+ MinStack . prototype . pop = function ( ) {
18
+ if ( this . stack . length > 0 ) {
19
+ this . stack . pop ( )
20
+ }
21
+ } ;
22
+
23
+ /**
24
+ * @return {number }
25
+ */
26
+ MinStack . prototype . top = function ( ) {
27
+ if ( this . stack . length > 0 ) {
28
+ return this . stack [ this . stack . length - 1 ] . val
29
+ }
30
+ } ;
31
+
32
+ /**
33
+ * @return {number }
34
+ */
35
+ MinStack . prototype . getMin = function ( ) {
36
+ if ( this . stack . length > 0 ) {
37
+ return this . stack [ this . stack . length - 1 ] . min
38
+ }
39
+ } ;
Original file line number Diff line number Diff line change @@ -85,6 +85,48 @@ class MinStack {
85
85
}
86
86
```
87
87
88
+ ``` javascript
89
+ var MinStack = function () {
90
+ this .stack = []
91
+ };
92
+
93
+ /**
94
+ * @param {number} x
95
+ * @return {void}
96
+ */
97
+ MinStack .prototype .push = function (x ) {
98
+ let min = this .stack .length === 0 ? x : this .stack [this .stack .length - 1 ].min
99
+ this .stack .push ({val: x, min: Math .min (min, x)})
100
+ };
101
+
102
+ /**
103
+ * @return {void}
104
+ */
105
+ MinStack .prototype .pop = function () {
106
+ if (this .stack .length > 0 ){
107
+ this .stack .pop ()
108
+ }
109
+ };
110
+
111
+ /**
112
+ * @return {number}
113
+ */
114
+ MinStack .prototype .top = function () {
115
+ if (this .stack .length > 0 ) {
116
+ return this .stack [this .stack .length - 1 ].val
117
+ }
118
+ };
119
+
120
+ /**
121
+ * @return {number}
122
+ */
123
+ MinStack .prototype .getMin = function () {
124
+ if (this .stack .length > 0 ) {
125
+ return this .stack [this .stack .length - 1 ].min
126
+ }
127
+ };
128
+
129
+ ```
88
130
## 结语
89
131
90
132
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
You can’t perform that action at this time.
0 commit comments