Skip to content

Valid Parentheses

EasyStack
Decode it first. Clues, constraints, pattern and plan before any code.

Given a string s made only of the characters ()[]{}, return true if every bracket is closed by the same type of bracket, in the right order. An opening bracket must be closed before any bracket opened earlier is closed.

"()[]{}"   →  true
"{[]}"     →  true
"([)]"     →  false   (] closes while ( is still the latest open)

Constraints

  • 0 <= s.length <= 10^4
  • s contains only the characters ()[]{}.
  • An empty string counts as valid.