Valid Parentheses

Problem Given a string containing only the bracket characters ()[]{}, determine whether it is well-formed: every opening bracket is closed by a matching bracket of the same type, and brackets are closed in the correct (properly nested) order.

Input / Output

  • Input: a string s of bracket characters.
  • Output: true if the brackets are balanced and correctly nested, false otherwise.

Constraints

  • 1 <= |s| <= 10^4.
  • The string contains only the six bracket characters.

Example

  • "([{}])" -> true
  • "([)]" -> false (closing order is wrong even though counts match)
  • "(" -> false (unclosed)
added …
LeaderboardSalaryAccount