Skip to content

Commit 579b6e3

Browse files
authored
Added remove duplicates
1 parent 4c265d4 commit 579b6e3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Recursion/remove_duplicates.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
#include <string.h>
3+
using namespace std;
4+
void removeduplicates(char input[]){
5+
if(input[0]=='\0'){
6+
return ;//if it is empty string
7+
}
8+
if(input[0]==input[1]){//checking for consecutive duplicate
9+
for(int i=0;input[i]!='\0';i++){
10+
input[i]=input[i+1];//shift to left
11+
}
12+
removeduplicates(input);
13+
}else{
14+
removeduplicates(input+1);
15+
}
16+
}
17+
18+
int main() {
19+
char input[1000];
20+
cin.getline(input,1000);
21+
removeduplicates(input);
22+
cout<<input;
23+
}
24+
/*Example
25+
aaaabbbbb
26+
O/p ab
27+
*/

0 commit comments

Comments
 (0)