From 3d78960e74d410b6b15f30db976b5caa78bac26f Mon Sep 17 00:00:00 2001 From: hyejjun Date: Fri, 20 Sep 2024 14:00:33 +0900 Subject: [PATCH 1/2] Valid Parentheses --- valid-parentheses/hyejjun.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 valid-parentheses/hyejjun.js diff --git a/valid-parentheses/hyejjun.js b/valid-parentheses/hyejjun.js new file mode 100644 index 000000000..ea7debcea --- /dev/null +++ b/valid-parentheses/hyejjun.js @@ -0,0 +1,26 @@ +/** + * @param {string} s + * @return {boolean} + */ +var isValid = function (s) { + const stack = []; + const map = { + ')': '(', + '}': '{', + ']': '[' + }; + + for (let i = 0; i < s.length; i++) { + const char = s[i]; + + if (char === '(' || char === '{' || char === '[') { + stack.push(char); + } else { + if (stack.length === 0 || stack.pop() !== map[char]) { + return false; + } + } + } + + return stack.length === 0; +}; \ No newline at end of file From 9e5ef35261ed0e24fe1291fcfb7eff5ffde9412c Mon Sep 17 00:00:00 2001 From: hyejjun Date: Fri, 20 Sep 2024 14:09:05 +0900 Subject: [PATCH 2/2] line break --- valid-parentheses/hyejjun.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valid-parentheses/hyejjun.js b/valid-parentheses/hyejjun.js index ea7debcea..0c5f6c311 100644 --- a/valid-parentheses/hyejjun.js +++ b/valid-parentheses/hyejjun.js @@ -23,4 +23,4 @@ var isValid = function (s) { } return stack.length === 0; -}; \ No newline at end of file +};