Zero To DSAZero To DSA
Privacy Policy
Min Stack

Valid Parentheses

easy
Time: O(n)
Space: O(n)

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is valid if brackets close in the correct order.

Constraints

  • 1 <= s.length <= 10⁴

Examples

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