Balanced Parentheses
EasyP1Coding
Given a string s made only of the characters (, ), {, }, [ and ], return true if the brackets are balanced: every opener is closed by the same type of bracket, in the correct order, and every closer has a matching opener.
Example 1
- Input
- s = "()[]{}"
- Output
- true
Example 2
- Input
- s = "(]"
- Output
- false
Example 3
- Input
- s = "([)]"
- Output
- false
- Why
- The brackets close in the wrong order.
Constraints
- 1 <= s.length <= 10^4
- s consists only of ()[]{} characters.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.