Skip to main content

Valid Parentheses

EasyPremium

Given a string s containing just the characters '(', ')', '{', '}', '[', and ']', write a function isValid to determine if the input string is valid. An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Return true if the string is valid, otherwise return false.

Examples

Input: s = "({" Output: false Input: s = "({[]()})" Output: true

In the first example, all brackets are properly closed and nested, so the result is false. In the second example, each type of bracket is matched and nested correctly, so the result is also true.

Constraints

  • The string s has a length of at most 10^4.