You are viewing a single comment's thread. Return to all comments →
Java 15
public static String superReducedString(String s) { List<Character> chList = s.chars() .mapToObj(c -> (char) c) .collect(Collectors.toList()); int index = 0; while (index < chList.size() - 1) { if (chList.get(index).equals(chList.get(index + 1))) { chList.remove(index); chList.remove(index); if (index > 0) index--; } else index++; } String result = chList.stream() .map(e -> e.toString()).collect(Collectors.joining()); return result.length() > 0 ? result : "Empty String"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
Java 15