Notice Period

Balanced Brackets

easy

Your editor's linter needs a bracket checker. A snippet contains only the characters ()[]{}.

The snippet is well-formed when every opener is closed by the matching bracket type, and closings happen in the reverse order of openings (no ( [ ) ] interleaving). Return True if the string s is well-formed, otherwise False. An empty string is well-formed.

Example 1
in s = "()"
out True
Example 2
in s = "([{}])"
out True
Every closer matches the most recent open bracket.
Example 3
in s = "(]"
out False
] arrives while ( is still the open bracket waiting.
Constraints
  • · 0 <= len(s) <= 10^4
  • · s contains only the characters ()[]{}
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.