Asked at

Valid Parentheses

Easy
Verified
StringStack~15 min

Given a string s containing just the characters ()[]{}, determine if the input string is valid.

A string is valid when every open bracket is closed by the same type of bracket, in the correct order, and every close bracket has a matching open bracket.

Examples

in"()[]{}"
outtrue

Every bracket closes the matching open bracket in order.

in"(]"
outfalse

Brackets close in the wrong order.

Constraints

  • 1 ≤ s.length ≤ 10⁴
  • s consists only of the characters ()[]{}.

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.