2957.cpp (286B)
1 class Solution { 2 public: 3 int removeAlmostEqualCharacters(const string &word) const { 4 int res = 0; 5 6 for (int i = 0; i < size(word) - 1; i++) { 7 if (abs(word[i] - word[i + 1]) > 1) continue; 8 res++, i++; 9 } 10 11 return res; 12 } 13 };