Alternating Characters

  • + 0 comments
    def alternatingCharacters(s):
        # Write your code here
        res = 0
        for i in range(1, len(s)):
            if s[i-1] == s[i]:
                res += 1
        return res
    
    what do you think of this code for 'You are given a string containing characters  and  only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string.
    Your task is to find the minimum number of required deletions.' ??