Back to problems
Not started
Valid parentheses
EasyStuck?
Show a hintHide the hint
The correct partner for a closing bracket is always the most recent unmatched opening one, which is what a stack gives you.
The ideas behind this problem
Next in this lesson
How long until it gets warmerGiven a string containing only the characters ()[]{}, decide whether the brackets are balanced.
Brackets must close in the correct order, and every opening bracket must have a matching closing bracket of the same type.
Constraints#
1 <= length <= 100000
Input
s is one line holding the string.
Output
`true` if the brackets are balanced, otherwise `false`.
Examples
Input
()[]{}
Output
true
Every bracket closes in the right order.
Input
(]
Output
false
Something wrong with this problem? Report an issue
Ready to try it
Write your solution in C, C++, Java or Python and see every test case come back with the time and memory it took.
Free, and it stays free. No card.