diff --git a/valid-parentheses/robinyoon-dev.js b/valid-parentheses/robinyoon-dev.js new file mode 100644 index 000000000..5dc3b6754 --- /dev/null +++ b/valid-parentheses/robinyoon-dev.js @@ -0,0 +1,27 @@ +/** + * @param {string} s + * @return {boolean} + */ +var isValid = function (s) { + + const tempArray = []; + const pairObject = { + ')': '(', + '}': '{', + ']': '[' + } + + for (const ch of s) { + if (ch === '(' || ch === '{' || ch === '[') { + tempArray.push(ch); + } else { + if (tempArray.pop() !== pairObject[ch]) { + return false; + } + } + } + + return tempArray.length === 0; +}; + +