Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};