Remove Adjacent Almost-Equal Characters - 30 ms Beats 99.11% of users with Python3
Complexity\n- Time complexity: The time complexity is O(n), where n is the length of the input string. The loop iterates through each character once.\n Add your
# Complexity\n- Time complexity: The time complexity is O(n), where n is the length of the input string. The loop iterates through each character once.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: The space complexity is O(1) as the additional space used (variables n, count, and i) does not depend on the size of the input.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def removeAlmostEqualCharacters(self, word: str) -> int:\n        # Get the length of the input string\n        n = len(word)\n\n        # Initialize the count of pairs with almost equal characters\n        count = 0\n\n        # Start iterating from the second character\n        i = 1\n\n        # Iterate through the characters of the string\n        while i < n:\n            # Check if the absolute difference in ASCII values is less than or equal to 1\n            if abs(ord(word[i-1]) - ord(word[i])) <= 1:\n                # Increment the count if the condition is met\n                count += 1\n                # Move to the next pair by skipping one character\n                i += 1\n\n            # Move to the next character for the next iteration\n            i += 1\n\n        # Return the final count\n        return count\n        \n```
['Python3']