Question: Given a string, returns a new string obtained by successively removing all adjacent matching characters. For example, given abbe, the method returns ac, and
Given a string, returns a new string obtained by successively removing all adjacent matching characters. For example, given "abbe", the method returns "ac", and given "abcddcbeffg", the method returns "seg". Note that multiple iterations may be required for the latter; that is, after removing the matching "dd" and "ff", the resulting string is "abccbeg", which now has a matching pair "cc"; after removing "cc", "the string is abbeg, which now has a matching pair "bb". You can assume that the given string contains alphabetic characters only. Oparam s given string @return string obtained by removing matching pairs of adjacent characters public static String cancelAdjacent Pairs(String s) // TODO return null;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
