Problem Statement
There is an unsafe way to write encrypted messages that works as follows. At most one contiguous substring of the original string is reversed and enclosed in square brackets. For example, the encrypted string "he[row oll]ld" represents the string "hello world". You will be given s, a String encrypted with this method, and you must return the original unencrypted String.
Definition
- Class:
- ReversingBrackets
- Method:
- removeBrackets
- Parameters:
- String
- Returns:
- String
- Method signature:
- String removeBrackets(String s)
- (be sure your method is public)
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character of s will be a lowercase letter ('a'-'z'), a space (' ') or a bracket ('[' and ']').
- s will contain either no bracket or exactly one '[' and one ']', and the '[' character will appear before the ']'.
Examples
"he[row oll]ld"
Returns: "hello world"
The example from the problem statement."ab[edc]f"
Returns: "abcdef"
"topcoder"
Returns: "topcoder"
Note that there can be no brackets."[desrever lla]"
Returns: "all reversed"