https://www.codewars.com/kata/52774a314c2333f0a7000688
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
Write a function that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return true if the string is valid, and false if it's invalid.
Examples
"()" => true
")(()))" => false
"(" => false
"(())((()())())" => true
Constraints
0 <= input.length <= 100
코드
function validParentheses(parens) {
let arr = [];
for(let i = 0; i < parens.length; i++){
if(parens[i] === '('){
arr.push('(');
} else{
if(arr.pop() !== '(') return false;
}
}
if(arr.length !== 0) return false;
return true;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Sort the odd (6 kyu) / JavaScript (0) | 2023.01.11 |
---|---|
[Codewars] Odd or Even? (7 kyu) / JavaScript (0) | 2023.01.10 |
[Codewars] Find the missing letter (6 kyu) / JavaScript (0) | 2023.01.07 |
[Codewars] Split Strings (6 kyu) / JavaScript (0) | 2023.01.06 |
[Codewars] Find the unique number (6 kyu) / JavaScript (0) | 2023.01.05 |
댓글