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 14958f6 commit 47e2958Copy full SHA for 47e2958
19-validParentheses.js
@@ -0,0 +1,36 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+var isValid = function (s) {
6
+ let arr = [];
7
+
8
+ let input = s.split("");
9
+ for (let i = 0; i < s.length; i++) {
10
+ if (s[i] === "(" || s[i] === "{" || s[i] === "[") {
11
+ arr.push(s[i]);
12
+ }
13
14
+ if (s[i] === ")") {
15
+ if (arr.pop() !== "(") {
16
+ return false;
17
18
19
20
+ if (s[i] === "}") {
21
+ if (arr.pop() !== "{") {
22
23
24
25
26
+ if (s[i] === "]") {
27
+ if (arr.pop() !== "[") {
28
29
30
31
32
33
+ return arr.length === 0;
34
+};
35
36
+console.log(isValid("({[[]]]})"));
0 commit comments