C++ O(N) One Pass with explanation
See my latest update in repo LeetCode\n\n## Solution 1.\n\nWhen we see a s[i] == \'?\', we set it as s[i - 1] + 1 and round it to \'a\' if necessary.\n\nWhen s[
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1.\n\nWhen we see a `s[i] == \'?\'`, we set it as `s[i - 1] + 1` and round it to `\'a\'` if necessary.\n\nWhen `s[i] == \'?\' && s[i + 1] != \'?\'`, there is a chance of conflict with `s[i + 1]`. If there is a conflict, we simply increment and round `s[i]` again.\n\n```cpp\n// OJ: https://leetcode.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(1)\nclass Solution {\npublic:\n    string modifyString(string s) {\n        int i = 0, N = s.size();\n        while (i < N) {\n            while (i < N && s[i] != \'?\') ++i;\n            int c = (i == 0 ? 0 : (s[i - 1] - \'a\' + 1) % 26);\n            while (i < N && s[i] == \'?\') {\n                s[i] = c + \'a\';\n                c = (c + 1) % 26;\n                if (i + 1 < N && s[i + 1] != \'?\' && s[i] == s[i + 1]) s[i] = c + \'a\';\n            }\n        }\n        return s;\n    }\n};\n```
[]