Valid Parentheses
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Input: s = "()"
Output: true
####Example 2:
Input: s = "()[]{}"
Output: true
Input: s = "(]"
Output: false
/**
* @param {string} s
* @return {boolean}
*/
var isValid = function(s) {
const brakets = {
')': '(',
'}': '{',
']': '['
}
const arr = []
for(let idx in s) {
const char = s[idx]
if(char === '(' || char === '{' || char === '[') {
arr.push(char)
} else {
if(arr[arr.length - 1] === brakets[char]) {
arr.pop();
} else return false
}
}
return arr.length === 0
};
Feedback은 언제나 환영입니다🤗