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
Post a Comment