Problem Statement
A series of brackets is complete if we can pair off each left bracket '[' with a right bracket ']' that occurs later in the series. Every bracket must participate in exactly one such pair.
Given a String text add the minimal number of brackets to the beginning and/or end of text to make it complete. Return the result.
Definition
- Class:
- CompletingBrackets
- Method:
- complete
- Parameters:
- String
- Returns:
- String
- Method signature:
- String complete(String text)
- (be sure your method is public)
Constraints
- text will have between 1 and 50 characters inclusive.
- text will contain only the characters '[' and ']'.
Examples
"[["
Returns: "[[]]"
Add two ']' to the end to make this complete."]["
Returns: "[][]"
Add one to the beginning and one to the end."[[[[]]]]"
Returns: "[[[[]]]]"
This is already complete.