Valid Parentheses
⚡ Difficulty: Easy 🏷️ Topic: Stack
Given a string containing only the characters ()[]{}, determine if the brackets are balanced and correctly nested.
Input
- A single line: the bracket string
s(may be empty).
Output
trueif the string is valid, otherwisefalse(lowercase).
Example
Input:
{[]}
Output:
true
—
Your code runs against test cases in a sandbox. Solutions persist in this browser. Read input from stdin, print the answer to stdout.
Want the approach? Read the Valid Parentheses solution or browse all problems.
Discussion
Newest first