You are viewing a single comment's thread. Return to all comments →
Or just build new string symbol by symbol
public static void main(String[] args) { final String str = new Scanner(System.in).next(); final char[] chars = new char[str.length()]; int c = 0; for(int i = 0; i < str.length(); i++) { final char nextChar = str.charAt(i); if(c > 0 && nextChar == chars[c - 1]) { c--; continue; } chars[c++] = nextChar; } System.out.println(c == 0 ? "Empty String" : new String(chars, 0, c)); }
Super Reduced String
You are viewing a single comment's thread. Return to all comments →
Or just build new string symbol by symbol