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 8fd950f commit 155fb24Copy full SHA for 155fb24
valid-parentheses/yuhyeon99.js
@@ -0,0 +1,38 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {boolean}
4
+ */
5
+var isValid = function(s) {
6
+ var stack = [];
7
+
8
+ var openDic = {
9
+ '{': '}',
10
+ '[': ']',
11
+ '(': ')'
12
+ };
13
+ var closeDic = {
14
+ '}': '{',
15
+ ']': '[',
16
+ ')': '('
17
18
19
+ for(let e of [...s]) {
20
+ if(!stack.length) {
21
+ stack.push(e);
22
+ continue;
23
24
25
+ const lastEle = stack.pop();
26
27
+ if(closeDic[e]) {
28
+ if(!openDic[lastEle]) return false;
29
+ if(openDic[lastEle] !== e) return false;
30
31
+ } else {
32
+ stack.push(lastEle);
33
34
+ }
35
36
37
+ return stack.length === 0;
38
+};
0 commit comments