File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed
solution/0000-0099/0032.Longest Valid Parentheses Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -230,12 +230,12 @@ function longestValidParentheses(s: string): number {
230
230
const n = s .length ;
231
231
const f: number [] = new Array (n + 1 ).fill (0 );
232
232
for (let i = 2 ; i <= n ; ++ i ) {
233
- if (s [i - 1 ] == ' )' ) {
234
- if (s [i - 2 ] == ' (' ) {
233
+ if (s [i - 1 ] === ' )' ) {
234
+ if (s [i - 2 ] === ' (' ) {
235
235
f [i ] = f [i - 2 ] + 2 ;
236
236
} else {
237
237
const j = i - f [i - 1 ] - 1 ;
238
- if (j && s [j - 1 ] == ' (' ) {
238
+ if (j && s [j - 1 ] === ' (' ) {
239
239
f [i ] = f [i - 1 ] + 2 + f [j - 1 ];
240
240
}
241
241
}
Original file line number Diff line number Diff line change @@ -189,12 +189,12 @@ function longestValidParentheses(s: string): number {
189
189
const n = s .length ;
190
190
const f: number [] = new Array (n + 1 ).fill (0 );
191
191
for (let i = 2 ; i <= n ; ++ i ) {
192
- if (s [i - 1 ] == ' )' ) {
193
- if (s [i - 2 ] == ' (' ) {
192
+ if (s [i - 1 ] === ' )' ) {
193
+ if (s [i - 2 ] === ' (' ) {
194
194
f [i ] = f [i - 2 ] + 2 ;
195
195
} else {
196
196
const j = i - f [i - 1 ] - 1 ;
197
- if (j && s [j - 1 ] == ' (' ) {
197
+ if (j && s [j - 1 ] === ' (' ) {
198
198
f [i ] = f [i - 1 ] + 2 + f [j - 1 ];
199
199
}
200
200
}
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ function longestValidParentheses(s: string): number {
2
2
const n = s . length ;
3
3
const f : number [ ] = new Array ( n + 1 ) . fill ( 0 ) ;
4
4
for ( let i = 2 ; i <= n ; ++ i ) {
5
- if ( s [ i - 1 ] == ')' ) {
6
- if ( s [ i - 2 ] == '(' ) {
5
+ if ( s [ i - 1 ] === ')' ) {
6
+ if ( s [ i - 2 ] === '(' ) {
7
7
f [ i ] = f [ i - 2 ] + 2 ;
8
8
} else {
9
9
const j = i - f [ i - 1 ] - 1 ;
10
- if ( j && s [ j - 1 ] == '(' ) {
10
+ if ( j && s [ j - 1 ] === '(' ) {
11
11
f [ i ] = f [ i - 1 ] + 2 + f [ j - 1 ] ;
12
12
}
13
13
}
You can’t perform that action at this time.
0 commit comments