驼峰问题:给定字符串ababc,若出现aba这样相邻相等的情况则称为驼峰现象,去掉所有的驼峰,代码如下:
s = "asdkajdknmnlclsos"
def clean_tuofeng(s):
if len(s)<3:
return s
while True:
for idx in range(1,len(s)-2):
if s[idx-1]==s[idx+1]:
temp = s[0:idx-1] + s[idx+2:]
s = temp
break
elif idx == len(s)-3:
if s[-1] == s[-3]:
s = s[0:len(s)-3]
return s
# print(s)
s = clean_tuofeng(s)
print(s)