s
is even. If not, return false
because a valid parentheses string must have an even number of characters.validate
that takes the string s
, the locked
string, and a character op
representing the opening parenthesis.bal
(balance) and wild
(wildcards) to 0.s
:
op
, increment bal
.op
, decrement bal
.wild
.bal + wild
is negative, return false
.bal
is greater than wild
, return false
.validate
function twice: once with the original strings and op
as '('
, and once with the reversed strings and op
as ')'
.validate
return true
, the string can be made valid, so return true
. Otherwise, return false
.