You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
The third solution doesn't work for "()()()((".
Expected false got undefined.
Fixed solution:
function validParentheses(parens){
var n = 0;
for (var i = 0; i < parens.length; i++) {
if (parens[i] == '(') n++;
if (parens[i] == ')') n--;
if (n < 0) return false;
}
if (n === 0) {
return true;
}
if (n > 0) { // Have to return something when n > 0.
return false;
}