Valid Parentheses
Easy
LC #20
stackstringmatchingNot attempted yet
You get a string s made only of the characters
( ) [ ] { }. Return True if it is valid:
- every opener is closed by a closer of the same type,
- brackets close in the correct order (the most recently opened one closes first),
- every closer has a matching opener.
Example 1
Input: s = "()"
Output: True
Example 2
Input: s = "()[]{}"
Output: True
Example 3
Input: s = "(]"
Output: False
Explanation: ( is closed by the wrong type.
Example 4
Input: s = "([])"
Output: True
Constraints
- 1 <= len(s) <= 10^5
- s contains only ()[]{}