有一个像它的字符串
dxabcabcyyyydxycxcxz
Run Code Online (Sandbox Code Playgroud)
我想将它合并到
dxabcydxycxz
Run Code Online (Sandbox Code Playgroud)
其他例子: ddxddx - > dxdx,abbab - > abab.
规则是:
if (adjacent and same): merge
# Such as 'abc',they are same and , so I will delete one of them .
# Although 'dx' is same as 'dx',they are nonadjacent,so I do not delete any of them
# If one character has been deleted, we don't delete any sub-string include it
Run Code Online (Sandbox Code Playgroud)
我在python的代码中完成了它,但是当它在一个长字符串中时它很慢.
# original string
mystr = "dxabcabcyyyydxycxcxz"
str_len = len(mystr)
vis = [1] *str_len #Use a …Run Code Online (Sandbox Code Playgroud)