Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Third solution #3

@Subho24

Description

@Subho24

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;
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions