Super Reduced String

  • + 0 comments
    public static string superReducedString(string s)
    {
        if(s.Length == 1) return s;        
        var i=1;
        while(i < s.Length){
            if(s.Substring(i-1, 1) == s.Substring(i, 1)){
                s = s.Remove(i-1, 2);
                if(i>1) i--;
            }
            else {
                i++;
            }
        }
        return s == "" ? "Empty String" : s;
    }