remove duplicate recursion

 #include <iostream>

#include <string>


using namespace std;


string removed(string s){

    if(s.length()==0){

        return "";

        

    }

    char ch=s[0];

    string ans=removed(s.substr(1));

    

    if(ch==ans[0]){

        return ans;

    }

    

    return ch+ans;

    

}


int main() {

    cout<<removed("aabbccddeee");


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings