File tree Expand file tree Collapse file tree 12 files changed +242
-272
lines changed
104-maximum-depth-of-binary-tree
1143-longest-common-subsequence
122-best-time-to-buy-and-sell-stock-ii
300-longest-increasing-subsequence
309-best-time-to-buy-and-sell-stock-with-cooldown
513-find-bottom-left-tree-value Expand file tree Collapse file tree 12 files changed +242
-272
lines changed Original file line number Diff line number Diff line change 1
- https://ojeveryday.com/
2
-
3
- https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/gitbook
4
-
5
- https://github.com/garciparedes
6
-
7
- https://garciparedes.me/#headers
8
-
9
- - Array
10
-
11
- - [x] 4
12
- - [x] 11
13
- - [ ] 15
14
- - [x] 16
15
- - [ ] 18
16
- - [x] 26
17
- - [x] 27
18
- - [x] 34
19
- - [x] 35
20
- - [ ] 39
21
- - [ ] 40
22
- - [x] 42
23
- - [ ] 45
24
- - [ ] 55
25
- - [x] 56
26
- - [x] 66
27
- - [x] 73
28
- - [ ] 78
29
- - [x] 80
30
- - [ ] 88
31
- - [ ] 90
32
-
33
- - Backtracking
34
-
35
- - [ ] 17
36
- - [ ] 22
37
- - [ ] 39
38
- - [ ] 40
39
- - [ ] 46
40
- - [ ] 47
41
- - [ ] 60
42
- - [ ] 77
43
- - [ ] 78
44
- - [ ] 90
45
- - [ ] 131
46
- - [ ] 211
47
- - [ ] 216
48
- - [ ] 306
49
- - [ ] 357
50
- - [ ] 872
51
-
52
- - Breadth First Search
53
-
54
- - [ ] 101
55
- - [ ] 103
56
- - [ ] 107
57
- - [ ] 111
58
- - [ ] 199
59
- - [ ] 200
60
- - [ ] 279
61
- - [ ] 513
62
- - [ ] 515
63
- - [ ] 542
64
- - [ ] 690
65
- - [ ] 744
66
- - [ ] 801
67
- - [ ] 877
68
- - [ ] 884
69
-
70
- - Depth First Search
71
-
72
- - [x] 100
73
- - [x] 101
74
- - [x] 108
75
- - [x] 110
76
- - [ ] 111
77
- - [x] 112
78
- - [x] 113
79
- - [x] 129
80
- - [ ] 199
81
- - [ ] 200
82
- - [ ] 257
83
- - [ ] 337
84
- - [ ] 394
85
- - [ ] 473
86
- - [ ] 491
87
- - [ ] 494
88
- - [ ] 513
89
- - [ ] 515
90
- - [ ] 542
91
-
92
- - Dynamic Programming
93
-
94
- - [ ] 5
95
- - [x] 53
96
- - [x] 62
97
- - [x] 64
98
- - [x] 70
99
- - [ ] 91
100
- - [x] 120
101
- - [x] 121
102
- - [ ] 152
103
- - [x] 198
104
- - [ ] 264
105
- - [ ] 279
106
- - [ ] 300
107
- - [ ] 309
108
- - [ ] 322
109
- - [ ] 338
110
- - [ ] 343
111
- - [ ] 357
112
- - [ ] 376
113
-
114
- - Greedy
115
-
116
- - [ ] 45
117
- - [ ] 55
118
- - [ ] 122
119
- - [ ] 134
120
- - [ ] 376
121
- - [ ] 392
122
- - [ ] 402
123
- - [ ] 406
124
- - [ ] 435
125
- - [ ] 198
126
- - [ ] 264
127
- - [ ] 279
128
- - [ ] 300
129
- - [ ] 309
130
- - [ ] 322
131
- - [ ] 338
132
- - [ ] 343
133
- - [ ] 357
134
- - [ ] 376
135
-
136
- - Hash Table
137
-
138
- - [ ] 3
139
- - [ ] 18
140
- - [ ] 36
141
- - [ ] 49
142
- - [ ] 76
143
- - [ ] 136
144
- - [ ] 202
145
- - [ ] 204
146
- - [ ] 217
147
- - [ ] 219
148
- - [ ] 347
149
- - [ ] 349
150
- - [ ] 350
151
- - [ ] 387
152
- - [ ] 389
153
- - [ ] 447
154
- - [ ] 454
155
- - [ ] 525
156
- - [ ] 594
157
-
158
- - Linked List
159
-
160
- - [ ] 21
161
- - [ ] 83
162
- - [ ] 141
163
- - [ ] 148
164
- - [ ] 160
165
- - [ ] 203
166
- - [ ] 206
167
- - [ ] 234
168
- - [ ] 237
169
- - [ ] 445
170
- - [ ] 766
171
- - [ ] 908
172
-
173
- - Tree
174
-
175
- - [ ] 94
176
- - [ ] 100
177
- - [ ] 101
178
- - [ ] 103
179
- - [ ] 104
180
- - [ ] 107
181
- - [ ] 108
182
- - [ ] 110
183
- - [ ] 111
184
- - [ ] 112
185
- - [ ] 113
186
- - [ ] 129
187
- - [ ] 144
188
- - [ ] 173
189
- - [ ] 226
190
- - [ ] 235
191
- - [ ] 257
192
- - [ ] 297
193
- - [ ] 404
194
-
195
- - Two Pointers
196
-
197
- - [ ] 3
198
- - [ ] 16
199
- - [ ] 26
200
- - [ ] 27
201
- - [ ] 80
202
- - [ ] 141
203
- - [ ] 167
204
- - [ ] 209
205
- - [ ] 234
206
- - [ ] 283
207
- - [ ] 287
208
- - [ ] 344
209
- - [ ] 349
210
- - [ ] 350
1
+ https://ojeveryday.com/
2
+
3
+ https://labuladong.gitbook.io/algo/di-ling-zhang-bi-du-xi-lie/gitbook
4
+
5
+ https://github.com/garciparedes
6
+
7
+ https://garciparedes.me/#headers
8
+
9
+ - Array +12
10
+
11
+ - [ ] 15
12
+ - [ ] 18
13
+ - [ ] 39
14
+ - [ ] 40
15
+ - [ ] 45
16
+ - [ ] 55
17
+ - [ ] 78
18
+ - [ ] 88
19
+ - [ ] 90
20
+
21
+ - Backtracking
22
+
23
+ - [ ] 17
24
+ - [ ] 22
25
+ - [ ] 39
26
+ - [ ] 40
27
+ - [ ] 46
28
+ - [ ] 47
29
+ - [ ] 60
30
+ - [ ] 77
31
+ - [ ] 78
32
+ - [ ] 90
33
+ - [ ] 131
34
+ - [ ] 211
35
+ - [ ] 216
36
+ - [ ] 306
37
+ - [ ] 357
38
+ - [ ] 872
39
+
40
+ - Breadth First Search +5
41
+
42
+ - [ ] 107
43
+ - [ ] 542
44
+ - [ ] 801
45
+ - [ ] 877
46
+
47
+ - Depth First Search +8
48
+
49
+ - [ ] 111
50
+ - [ ] 199
51
+ - [ ] 337
52
+ - [ ] 491
53
+ - [ ] 494
54
+ - [ ] 513
55
+ - [ ] 515
56
+ - [ ] 542
57
+
58
+ - Dynamic Programming +7
59
+
60
+ - [ ] 357
61
+ - [ ] 376
62
+ - [ ] 1143
63
+ - [ ] 5
64
+ - [ ] 91
65
+ - [ ] 152
66
+ - [ ] 264
67
+ - [ ] 279
68
+ - [ ] 300
69
+ - [ ] 309
70
+ - [ ] 322
71
+ - [ ] 343
72
+
73
+ - Greedy
74
+
75
+ - [ ] 134
76
+ - [ ] 376
77
+ - [ ] 392
78
+ - [ ] 402
79
+ - [ ] 406
80
+ - [ ] 435
81
+ - [ ] 198
82
+ - [ ] 264
83
+ - [ ] 279
84
+ - [ ] 300
85
+ - [ ] 309
86
+ - [ ] 322
87
+ - [ ] 338
88
+ - [ ] 343
89
+ - [ ] 357
90
+ - [ ] 376
91
+
92
+ - [ ] 45
93
+ - [ ] 55
94
+ - [ ] 122
95
+
96
+ - Hash Table +6
97
+
98
+ - [ ] 389
99
+ - [ ] 447
100
+ - [ ] 454
101
+ - [ ] 525
102
+ - [ ] 594
103
+ - [ ] 18
104
+
105
+ - Linked List
106
+
107
+ - [ ] 83
108
+ - [ ] 141
109
+ - [ ] 148
110
+ - [ ] 160
111
+ - [ ] 203
112
+ - [ ] 206
113
+ - [ ] 234
114
+ - [ ] 237
115
+ - [ ] 445
116
+ - [ ] 766
117
+ - [ ] 908
118
+ - [ ] 21
119
+
120
+ - Tree +4
121
+
122
+ - [ ] 103
123
+ - [ ] 107
124
+ - [ ] 226
125
+ - [ ] 235
126
+ - [ ] 404
127
+
128
+ - Two Pointers +7
129
+
130
+ - [ ] 3
131
+ - [ ] 16
Original file line number Diff line number Diff line change 1
- // HELP:
2
-
3
1
export function maxDepth ( treeNode ) {
4
2
if ( ! treeNode ) return 0 ;
5
3
return Math . max ( maxDepth ( treeNode . left ) , maxDepth ( treeNode . right ) ) + 1 ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } text1
3
+ * @param {string } text2
4
+ * @return {number }
5
+ */
6
+ var longestCommonSubsequence = function ( text1 , text2 ) {
7
+ const m = text1 . length ;
8
+ const n = text2 . length ;
9
+ const dp = new Array ( m + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( n + 1 ) . fill ( 0 ) ) ;
10
+
11
+ for ( let i = 1 ; i < m + 1 ; i ++ ) {
12
+ const c1 = text1 . charAt ( i - 1 ) ;
13
+ for ( let j = 1 ; j < n + 1 ; j ++ ) {
14
+ const c2 = text2 . charAt ( j - 1 ) ;
15
+ if ( c1 === c2 ) {
16
+ dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + 1 ;
17
+ } else {
18
+ dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;
19
+ }
20
+ }
21
+ }
22
+
23
+ return dp [ m ] [ n ] ;
24
+ } ;
Original file line number Diff line number Diff line change 1
- // Time Complexity O(n)
2
- // Space Complexity O(1)
3
-
4
- export function maxProfit2 ( prices ) {
5
- let maxProfit = 0 ;
6
- for ( let i = 1 ; i < prices . length ; i ++ ) {
7
- const different = prices [ i ] - prices [ i - 1 ] ;
8
- if ( different > 0 ) maxProfit += different ;
9
- }
10
-
11
- return maxProfit ;
12
- }
1
+ // Time Complexity O(n)
2
+ // Space Complexity O(1)
3
+
4
+ export function maxProfit2 ( prices ) {
5
+ let maxProfit = 0 ;
6
+ for ( let i = 1 ; i < prices . length ; i ++ ) {
7
+ const different = prices [ i ] - prices [ i - 1 ] ;
8
+ if ( different > 0 ) maxProfit += different ;
9
+ }
10
+
11
+ return maxProfit ;
12
+ }
You can’t perform that action at this time.
0 commit comments