Java Greedy O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \nBe Greedy, when word[i] is almost the same with word[i - 1], always change word[i], whi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBe Greedy, when word[i] is almost the same with word[i - 1], always change word[i], which makes sure word[i] is never almost the same with word[i + 1]. It is always possible since we have 26 candidates. Then i += 2 to continue the loop. \n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\nclass Solution {\n    public int removeAlmostEqualCharacters(String word) {\n        char[] arr = word.toCharArray();\n        int i = 1, res = 0; \n        while (i < arr.length) {\n            if (isAlmost(arr[i], arr[i - 1])) {\n                res++;\n                i += 2;\n            } else {\n                i++;\n            }\n        }\n        return res;\n    }\n\n    private boolean isAlmost(char a, char b) {\n        return a == b || a - b == 1 || a - b == -1;\n    }\n}\n```
['Java']