File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -12,3 +12,5 @@ Data Structures and Algorithms Patterns implemented in Python.
12
12
- [x] [ Recursion on Arrays] ( Recursion/Arrays )
13
13
- [x] [ Merge Sort Array] ( Recursion/Arrays/mergesort.py )
14
14
- [x] [ Quick Sort Array] ( Recursion/Arrays/quicksort.py )
15
+ - [x] [ Recursion on Strings] ( Recursion/Strings )
16
+ - [x] [ Remove Consecutive Duplicates] ( Recursion/Strings/removeconsecutiveduplicates.py )
Original file line number Diff line number Diff line change
1
+ '''
2
+ Given a string S, remove all the consecutive duplicates. Here we keep one character and remove all subsequent same characters.
3
+
4
+ Examples:
5
+
6
+ Input : aaaaabbbbbb
7
+ Output : ab
8
+
9
+ Input : aabccba
10
+ Output : abcba
11
+
12
+ '''
13
+
14
+ def removeconsecutivestring (Str ):
15
+ if len (Str )< 2 :
16
+ return Str
17
+ if Str [0 ]!= Str [1 ]:
18
+ return Str [0 ]+ removeconsecutivestring (Str [1 :])
19
+ return removeconsecutivestring (Str [1 :])
20
+
21
+ print (removeconsecutivestring ("aabccba" )) #abcba
You can’t perform that action at this time.
0 commit comments