You are viewing a single comment's thread. Return to all comments →
I really enjoy solving this with Java 8 :
public static String superReducedString(String s) { // Write your code here StringBuffer sb = new StringBuffer(s); char p = '!'; int i = 0; while(i< sb.length()){ char c = sb.charAt(i); if(c==p){ sb.deleteCharAt(i); i--; sb.deleteCharAt(i); i--; p = '!'; if(i<0){ i=0; } }else{ p = c; i++; } } String res =sb.toString(); if(res.length()==0){ return "Empty String"; } return res; }
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 →
I really enjoy solving this with Java 8 :