Skip to content

Commit

Permalink
Merge pull request #474 from hyejjun/main
Browse files Browse the repository at this point in the history
[ํ˜œ์ค€] Week6 ๋ฌธ์ œํ’€์ด
  • Loading branch information
hyejjun authored Sep 21, 2024
2 parents b21b003 + 9e5ef35 commit 26691e9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions valid-parentheses/hyejjun.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 26691e9

Please sign in to comment.