Problem Statement
Fox Ciel received a string as a birthday present. However, the string was too long for her, so she decided to make it shorter by erasing some characters.
The erasing process will look as follows:
For example, if she receives "cieeilll", she will change the string as follows: "cieeilll" -> "ciilll" -> "clll" -> "cl". You are given a String s. Return the string she will get after she erases characters as described above.
The erasing process will look as follows:
- Find the smallest i such that the i-th character and the (i+1)-th character of the string are same.
- If there is no such i, end the process.
- Remove the i-th and the (i+1)-th character of the string, and repeat from 1.
For example, if she receives "cieeilll", she will change the string as follows: "cieeilll" -> "ciilll" -> "clll" -> "cl". You are given a String s. Return the string she will get after she erases characters as described above.
Definition
- Class:
- ErasingCharacters
- Method:
- simulate
- Parameters:
- String
- Returns:
- String
- Method signature:
- String simulate(String s)
- (be sure your method is public)
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character in s will be a lowercase letter ('a'-'z').
Examples
"cieeilll"
Returns: "cl"
This is the example from the statement."topcoder"
Returns: "topcoder"
She won't erase any characters at all."abcdefghijklmnopqrstuvwxyyxwvutsrqponmlkjihgfedcba"
Returns: ""
"bacaabaccbaaccabbcabbacabcbba"
Returns: "bacbaca"
"eel"
Returns: "l"