File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
src/leet-code/0020-valid-parentheses Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change
1
+ // Regex matching adjacent open-close pairs (), {}, and [].
1
2
const adjacentParens = / \( \) | \{ \} | \[ \] / g
2
3
3
4
/**
@@ -12,10 +13,10 @@ const adjacentParens = /\(\)|\{\}|\[\]/g
12
13
*/
13
14
const hasValidParentheses = ( str ) => {
14
15
if ( str . length === 0 ) return true
15
- else if ( str . length % 2 !== 0 ) return false
16
+ if ( str . length % 2 !== 0 ) return false
16
17
17
18
let currentStr = str
18
- let prevLength
19
+ let prevLength = 0
19
20
20
21
// Remove adjacent pairs until there are none (until string size doesn't
21
22
// change)
@@ -29,5 +30,5 @@ const hasValidParentheses = (str) => {
29
30
30
31
module . exports = {
31
32
fun : hasValidParentheses ,
32
- id : 'string-remove '
33
+ id : 'string-replace '
33
34
}
You can’t perform that action at this time.
0 commit comments