backbenchcode
← all problemsnext: Rolling Window Mean
#02EasyData Structures · 64% acceptance

Valid Bracket Sequence

StackString

Given a string `s` containing only the characters ( ) [ ] { }, determine if the brackets are correctly matched and nested.

Every opening bracket must close in the right order — just like every reagent added must eventually be accounted for.

Examples

Input: s = "()[]{}"

Output: true

Input: s = "([)]"

Output: false

Note: The square bracket closes before the round one it contains.

Constraints

Hints

solution.pyPython 3
1
2
3
4
5
6
7
8
9
10
Test console

// hit Run to execute the sample tests

// Interactive editor preview. Live code execution arrives with your early-access cohort.