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 fd8d099 commit 2576e20Copy full SHA for 2576e20
valid-parentheses/moonjonghoo.js
@@ -0,0 +1,18 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+var isValid = function (s) {
6
+ let object = { ")": "(", "}": "{", "]": "[" };
7
+ let stack = [];
8
+ for (let char of s) {
9
+ if (char === "(" || char === "{" || char === "[") {
10
+ stack.push(char);
11
+ } else {
12
+ if (stack.length === 0 || stack.pop() !== object[char]) {
13
+ return false;
14
+ }
15
16
17
+ return stack.length === 0;
18
+};
0 commit comments