Valid Parentheses

Given a string s consisting only of the characters '(', ')', '{', '}', '[' and ']', determine if the string is valid. A valid string must have open brackets closed by the same type of brackets, must close brackets in the correct order, and every closing bracket must have a corresponding open bracket of the same type.

Constraints

  • 1 <= s.length <= 10^4
  • s consists only of '()[]{}'.
Saving… · 3 lines
class Solution:
def isValid(self, s: str) -> bool:

Console

Click Run to execute sample tests.