From 92227352734d340300ef46fbb10001c68612c9a2 Mon Sep 17 00:00:00 2001 From: Robin Yoon Date: Tue, 16 Dec 2025 12:58:10 +0900 Subject: [PATCH] valid-parentheses --- valid-parentheses/robinyoon-dev.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 valid-parentheses/robinyoon-dev.js diff --git a/valid-parentheses/robinyoon-dev.js b/valid-parentheses/robinyoon-dev.js new file mode 100644 index 0000000000..5dc3b6754d --- /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; +}; + +