#K1121. Balanced Brackets

    ID: 23418 Type: Default 1000ms 256MiB

Balanced Brackets

Balanced Brackets

You are given a string ( s ) that consists solely of the characters '(', ')', '{', '}', '[' and ']'. The task is to determine whether the brackets in the string are balanced. A string is considered balanced if and only if:

  1. Every opening bracket has a corresponding closing bracket of the same type.
  2. The pairs of brackets are properly nested.

For example, the string (){}[] is balanced, but the string ([)] is not. Use a stack-based approach to solve this problem.

inputFormat

The input is read from standard input and consists of a single line string ( s ) containing only the characters '(', ')', '{', '}', '[' and ']'. The string may be empty.

outputFormat

Output to standard output a single line: either True if the input string has balanced brackets, or False otherwise.## sample

(){}[]
True