You are viewing a single comment's thread. Return to all comments →
Here is a python O(n) time and O(1) space solution:
def alternatingCharacters(s): ch = s[0] remove = 0 for i in range(1, len(s)): if s[i] == ch: remove += 1 if s[i] != ch: ch = s[i] return remove
Seems like cookies are disabled on this browser, please enable them to open this website
Alternating Characters
You are viewing a single comment's thread. Return to all comments →
Here is a python O(n) time and O(1) space solution: