Skip to content

Commit 9222735

Browse files
committed
valid-parentheses
1 parent 891ad63 commit 9222735

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

valid-parentheses/robinyoon-dev.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function (s) {
6+
7+
const tempArray = [];
8+
const pairObject = {
9+
')': '(',
10+
'}': '{',
11+
']': '['
12+
}
13+
14+
for (const ch of s) {
15+
if (ch === '(' || ch === '{' || ch === '[') {
16+
tempArray.push(ch);
17+
} else {
18+
if (tempArray.pop() !== pairObject[ch]) {
19+
return false;
20+
}
21+
}
22+
}
23+
24+
return tempArray.length === 0;
25+
};
26+
27+

0 commit comments

Comments
 (0)