SDE Path

Check for Balanced Parentheses

Easy

Check for Balanced Parentheses

Determine whether a string of brackets is balanced using a stack.

Input format

A single line containing a string of the brackets ()[]{}.

Output format

Print true if the brackets are balanced, otherwise false.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
()[]{}
Expected output
true
Example 2
Input
(]
Expected output
false