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\">
public static String stringClean(String str) {
if (str == null || "".equals(str)) {
return str;
}
char lastChar = str.charAt(0);
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.append(lastChar);
for (int index = 1; index < str.length(); index++) {
char next = str.charAt(index);
if (lastChar != next) {
resultBuilder.append(next);
lastChar = next;
}
}
return resultBuilder.toString();
}