We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2813e11 + d898609 commit 461d95fCopy full SHA for 461d95f
Recursion/remove_duplicates.cpp
@@ -0,0 +1,28 @@
1
+/*Given a string S, remove consecutive duplicates from it recursively*/
2
+#include <iostream>
3
+#include <string.h>
4
+using namespace std;
5
+void removeduplicates(char input[]){
6
+ if(input[0]=='\0'){
7
+ return ;//if it is empty string
8
+ }
9
+ if(input[0]==input[1]){//checking for consecutive duplicate
10
+ for(int i=0;input[i]!='\0';i++){
11
+ input[i]=input[i+1];//shift to left
12
13
+ removeduplicates(input);
14
+ }else{
15
+ removeduplicates(input+1);
16
17
+}
18
+
19
+int main() {
20
+ char input[1000];
21
+ cin.getline(input,1000);
22
23
+ cout<<input;
24
25
+/*Example
26
+aaaabbbbb
27
+O/p ab
28
+*/
0 commit comments