i have the following problem
Given a string, return a \"cleaned\" string where adjacent chars that are the same have been reduced to a single char. So \"yyzzza\">
Looks like you are solving codingbat problems, it is good,
I m a beginner too. This exercise is supposed to be just using recursion
This is my solution:
public String stringClean(String str) {
if (str.length() <= 1)
return str;
String adj1 = str.substring(0,1);
String adj2 = str.substring(1,2);
String rest = str.substring(1);
if (adj1.equals(adj2)) {
return stringClean(rest);
} else
return adj1 + stringClean(rest);
}
Hope it helps