You are viewing a single comment's thread. Return to all comments →
Solution using Stack in java:
public static String superReducedString(String s) { String result = ""; Stack<Character> stack = new Stack<>(); int n = s.length(); for(int i = 0; i < n; i++){ char c = s.charAt(i); if(stack.empty() || c != stack.peek()) stack.push(c); else stack.pop(); } if(stack.empty()) result = "Empty String"; else for(char c: stack) result += c; return result; }
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 →
Solution using Stack in java: