19: Valid parentheses

Given a string, the string contains ( ) [ ] { }. Write a method to check if the string is valid

 

The string is valid if:

  • The input string is empty
  • Open brackets are closed by the same type of brackets
  • Open brackets are closed in the correct order

Example 1

Input: ({})

Output: true

Example 2

Input: [)

Output: false