Skip to content
CodeShare
All problems

Valid Parentheses

Check whether every bracket is closed in the right order.

EasyStringsStack

Given a string s made up only of the characters (, ), {, }, [ and ], decide whether it is valid.

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

Examples

Example 1
Input
s = "()"
Output
true
Example 2
Input
s = "()[]{}"
Output
true
Example 3
Input
s = "(]"
Output
false

Constraints

  • 1 <= s.length <= 10^4
  • s contains only the six bracket characters.