We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Super Reduced String
- Discussions
Super Reduced String
Super Reduced String
Sort by
recency
|
1712 Discussions
|
Please Login in order to post a comment
public static String superReducedString(String s) { char[] arr = s.toCharArray(); //Since String is immutable we can't directly alter the string so //use StringBuilder to store the altered String java.lang.StringBuilder sb = new java.lang.StringBuilder(); for(char c : arr){ if(sb.length()>0 &&(sb.charAt(sb.length()-1)==c)){ sb.deleteCharAt(sb.length()-1); }else{ sb.append(c); } } if(sb.length()==0){ return "Empty String"; } return sb.toString(); }
Python stack solution:
Solution using Stack in java:
Here is my c++ solution, you can watch the explanation here : https://youtu.be/XgJKCkb1EjQ