CodingEasy
Valid Parentheses
You’re given a string s that holds only the characters (, ), [, ], { and }. Return true if its brackets are balanced, and false otherwise.
Balanced means every opening bracket is closed by one of the same kind, brackets close in the reverse of the order they opened, and no closing bracket shows up without an open one to match.
Example 1
Input
s = "()[]{}"OutputtrueExample 2
Input
s = "([{}])"OutputtrueEach bracket closes after everything opened inside it.
Example 3
Input
s = "(]"OutputfalseA round bracket can’t be closed by a square one.
Example 4
Input
s = "([)]"OutputfalseThe square bracket opened last, so it has to close before the round one.
Constraints
- 1 ≤ s.length ≤ 10⁴
- s holds only the characters ()[]{}