Bracket Gate
Preview mode. Log in to edit, run, submit, and save progress.
Easy
Bracket Gate
A lock accepts a string made only of brackets: parentheses (), square brackets [], and curly brackets {}. The string is valid if every opening bracket is closed by the same type of bracket, and brackets close in the correct order. Return YES if the bracket string is valid. Otherwise, return NO.
Examples
Example 1
Input:
()[]{}Output:
YES
Approach hint
Opening brackets should wait until their matching closing bracket appears.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
solution.cpp