We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c21332b commit 3f52b76Copy full SHA for 3f52b76
20-valid-parentheses.js
@@ -1,3 +1,30 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+ const isValid = function(s) {
6
+ const stack = []
7
+ const n = s.length
8
+ for(let c of s) {
9
+ if(c === '(' || c === '{' || c === '[') stack.push(c)
10
+ else if(c === ')') {
11
+ if(stack[stack.length - 1] === '(') stack.pop()
12
+ else return false
13
+ }
14
+ else if(c === '}') {
15
+ if(stack[stack.length - 1] === '{') stack.pop()
16
17
18
+ else if(c === ']') {
19
+ if(stack[stack.length - 1] === '[') stack.pop()
20
21
22
23
+ return stack.length === 0
24
+};
25
+
26
+// another
27
28
/**
29
* @param {string} s
30
* @return {boolean}
0 commit comments