#152EasyStacks· Matching Pairs
Balanced Brackets Validator
Input format
`s`: a string of printable ASCII characters (no double quotes or backslashes).
Output format
`true` if the brackets in `s` are balanced, otherwise `false`.
Examples
Input: s = "f(a[0]) + {b}"
Output: true
The round, square and curly pairs are each opened and closed in a consistent nesting, and the letters are ignored.
Input: s = "([)]"
Output: false
The square bracket closes while the round bracket opened after it is still open, so the nesting is crossed.
Input: s = "(("
Output: false
Both openers are never closed; a leftover opener is also an error.
Constraints
- 0 <= s.length <= 10^5
- s contains printable ASCII characters only; it contains no double quote and no backslash.
- #stack
- #strings
- #parsing