Valid Parentheses
Return whether the bracket string is properly nested and matched. Each closing bracket must match the most recent unmatched opening bracket.
Example 1
s = "{[()]}"trueExplanation
Closers match the most recent openers in order: (), then [], then {}.
Example 2
s = "([)]"falseExplanation
The ) arrives while [ is the latest unmatched opener, violating nesting.
Example 3
s = "("falseExplanation
The opening parenthesis never receives a closer.
Example 4
s = ""trueExplanation
The empty sequence has no unmatched or misordered brackets.
Constraints
- 0 <= len(s) <= 10000
- Characters are ()[]{}
Function contract
isValidArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 33 cases, on your device.
"{[()]}"