Replace All ?'s to Avoid Consecutive Repeating Characters LeetCode solution in C++
1class Solution {2char update_char(char x, char y) {3char c = 'a';4while (c == x || c == y) {5c++;6}7return c;8}910public:11string modifyString(string s) {12int l = s.length();13char c;14if (s[0] == '?') {15c = update_char(s[0], s[1]);16s[0] = c;17}18if (s[l - 1] == '?') {19c = update_char(s[l - 2], s[l - 1]);20s[l - 1] = c;21}22for (int i = 1; i < l - 1; ++i) {23if (s[i] == '?') {24c = update_char(s[i - 1], s[i + 1]);25s[i] = c;26}27}28return s;29}30};