← Back to problems Solve on LeetCode →

Valid Parentheses

LeetCode 20 • Easy • Stack

Input: s = "()[]{}" → Output: true. Use a stack: push open brackets, pop and match on close. Stack empty at end = valid.

TimeO(n)
SpaceO(n)
Index: Stack: [ ] Result:
Current char
In stack
Matched
Mismatch
Current
Stack
[ ]
Result
Ready
Press Play. For each char: if open push; if close pop and match. Empty stack at end = valid.