Problem Statement
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
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"
"phhzonmhoiicmiopdhaopzqochdzpdocomhayiaiaymynpoyoq"
Returns: "pzonmhocmiopdhaopzqochdzpdocomhayiaiaymynpoyoq"
"lumrnjcwxeqpftdkeaoirxxnjamvgiknvipjgryfzdaoljqlic"
Returns: "lumrnjcwxeqpftdkeaoirnjamvgiknvipjgryfzdaoljqlic"
"bottwzhnwytoyubnbotwuztoutotttzyuuzohnzuolbtbbollt"
Returns: "bowzhnwytoyubnbotwuztoutotzyzohnzuolbtot"
"pfcfiitmjvijcswwyvplathfzzrrvrxrysnrcqklpmmekjkpcy"
Returns: "pfcftmjvijcsyvplathfvrxrysnrcqklpekjkpcy"
"rddrdssrrrrdddxrsxsrddrrrrrdrsxrxrrsdxrxssrsrxsdsx"
Returns: "xrsxsdrsxrxsdxrxrsrxsdsx"
"vppbpvpbdbbbdvvvpbvpbbvvvbppppbpbvbbvvppppbbbpdpbd"
Returns: "vbpvpbdbdvpbvpvpbvbpdpbd"
"ugzchppfhucfxafcfucjhggjgjgpzzhfzgafxhhhczgxhhgjha"
Returns: "ugzchfhucfxafcfucjhjgjgphfzgafxhczgxgjha"
"rurcmcdsmrcdddscmsrucsduscuudrmdrusucsmmdccdusdsms"
Returns: "rurcmcdsmrcdscmsrucsduscdrmdrusucsusdsms"
"odgywouyodwjyfdoyiyugfhjdguufgionecfghcgiynhydjyyw"
Returns: "odgywouyodwjyfdoyiyugfhjdgfgionecfghcgiynhydjw"
"cpaafwuhqurhuarbufaxxonuxwucoxcxfqxqrpxxxfcbcfawqo"
Returns: "cpfwuhqurhuarbufaonuxwucoxcxfqxqrpxfcbcfawqo"
"wlbksnjktm"
Returns: "wlbksnjktm"
"mmrwscgyyeho"
Returns: "rwscgeho"
"difddididfdiiidddfififidi"
Returns: "difididfdidfififidi"
"wksoaxbkshobugyzsbwl"
Returns: "wksoaxbkshobugyzsbwl"
"jwygypu"
Returns: "jwygypu"
"baiucuqjrzbqtjdzadubbdzuaridajburbbczjztjzqa"
Returns: "baiucuqjrzbqtjdzadudzuaridajburczjztjzqa"
"eeeeeeeeeeeeeeeeeeeee"
Returns: "e"
"esinghaaggn"
Returns: "esinghn"
"lsjnjdpcdptkclzbst"
Returns: "lsjnjdpcdptkclzbst"
"wwvovvoxwwowxxvoxovoxvovvxxxooxvwoowwxvxowooxovvoo"
Returns: "vxowvoxovoxvovwxvxowxo"
"cccccccccccccccccccccccccccccccccccccccccccccccccc"
Returns: ""
"b"
Returns: "b"
"abcca"
Returns: "aba"
"aba"
Returns: "aba"
"all"
Returns: "a"
"aaaa"
Returns: ""
"caacb"
Returns: "b"
"aaaab"
Returns: "b"