We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2bf811b commit 19d9ba7Copy full SHA for 19d9ba7
L-B/0022 ValidParentheses/ValidParentheses.js
@@ -0,0 +1,29 @@
1
+const ValidParentheses = (s) => {
2
+ var stack = [];
3
+
4
+ obj = {
5
+ "(": ")",
6
+ "{": "}",
7
+ "[": "]",
8
+ };
9
10
+ for (let i of s) {
11
+ if (Object.keys(obj).includes(i)) {
12
+ stack.push(i);
13
+ } else if (stack && obj[stack[stack.length - 1]] == i) {
14
+ stack.pop();
15
+ } else {
16
+ return false;
17
+ }
18
19
20
+ return stack.length === 0 ? true : false;
21
+};
22
23
+s = "()";
24
+s1 = "()[]{}";
25
+s2 = "(]";
26
27
+console.log(ValidParentheses(s));
28
+console.log(ValidParentheses(s1));
29
+console.log(ValidParentheses(s2));
0 commit comments