You are viewing a single comment's thread. Return to all comments →
I've a similar approach in C#
static string super_reduced_string(string s) { Stack<char> stack = new Stack<char>(); foreach (char c in s) { char top = (stack.Count==0)?' ':stack.Peek(); if (top == c) stack.Pop(); else stack.Push(c); } char[] reduced = stack.ToArray(); Array.Reverse(reduced); if (reduced.Length ==0 ) return "Empty String"; else return(new String(reduced)); }
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've a similar approach in C#