You are viewing a single comment's thread. Return to all comments →
I improved your code, it's a better choice use StringBuilder to delete, cause Strings is immutable in Java
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner n = new Scanner(System.in); String s = n.nextLine(); for(int i = 1; i < s.length() ; i++){ if (new Character(s.charAt(i)).equals(new Character(s.charAt(i -1)))){ s = new StringBuilder(s).deleteCharAt(i).deleteCharAt(i -1).toString(); i = 0; } } String response = (s.isEmpty()) ? "Empty String" : s; System.out.println(response); } }
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 improved your code, it's a better choice use StringBuilder to delete, cause Strings is immutable in Java