Skip to content

Commit c568523

Browse files
authored
Update 20-valid-parentheses.js
1 parent 3f52b76 commit c568523

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

20-valid-parentheses.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
const isValid = function(s) {
6+
const stack = []
7+
for(let c of s) {
8+
if(c === '(') stack.push(')')
9+
else if(c === '{') stack.push('}')
10+
else if(c === '[') stack.push(']')
11+
else if(stack.length === 0 || c !== stack.pop()) return false
12+
}
13+
return stack.length === 0
14+
};
15+
16+
17+
// another
18+
119
/**
220
* @param {string} s
321
* @return {boolean}

0 commit comments

Comments
 (0)