Last active
June 12, 2020 21:52
-
-
Save pyrofolium/44c4bf95a6cc08c8bde78cf659226c1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# string processing | |
# remove sequential duplicate characters from a string | |
# "aaabbccccccfffdde" -> "abcfde" | |
#"abcdefghijklmnop" | |
# b = num of boundaries | |
# n * log(n) | |
def remove_repeated(x: str) -> str: | |
if len(x) <= 1: | |
return x | |
else: | |
if x[0] == x[1]: | |
return remove_repeated(x[0] + x[2:]) | |
else: | |
return x[0] + remove_repeated(x[1:]) | |
def remove_repeated2(x: str) -> str: | |
acc = [] | |
for char in x: | |
if len(acc) == 0 or acc[-1] != char: | |
acc.append(char) | |
return "".join(acc) | |
# def addNumbers(a,b): | |
# sum = a + b | |
# return sum | |
# num1 = int(input()) | |
# num2 = int(input()) | |
# print("The sum is", addNumbers(num1, num2)) | |
print(remove_repeated("aaabbccccccafffdde")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment