← 返回 meta 的题目列表Min Remove to Make Valid Parentheses
类型:qbank
LeetCode 1249. Stack-based scan removing minimum parens to make the string valid. Multi-bracket-type extension is the canonical follow-up.
Requirements
Remove the minimum number of ( and ) so the resulting string is valid.
Two-pass: forward to mark unmatched ), backward (or stack) to mark unmatched (; build output skipping marked indices.
Follow-up: support multiple bracket types ()[]{} simultaneously. Single stack tracking expected closers handles it.
Notes
One-pass with a stack of indices is the cleanest implementation.
Multi-type follow-up needs careful invariant: stack pops only when type matches, otherwise mark for removal.
Preparation
Write LeetCode 1249 in <8 min.
Drill multi-bracket-type variant: stack of (index, expected_close_char) tuples.