beats 100% cpp soln
Intuition\nIf the input string has length 1 and the only character is \'?\', it replaces it with \'a\'. Otherwise, it returns the original string.\n\nIf the fir
# Intuition\nIf the input string has length 1 and the only character is \'?\', it replaces it with \'a\'. Otherwise, it returns the original string.\n\nIf the first character of the string is \'?\', it replaces it with \'a\' if the next character is \'a\', and with \'b\' otherwise.\n\nFor each \'?\' in the middle of the string (excluding the first and last characters), it replaces it with the lexicographically smallest character that is different from both the preceding and succeeding characters.\n\nIf the last character of the string is \'?\', it replaces it with \'a\' if the preceding character is \'a\', and with \'b\' otherwise.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n0(n*26)\n\n- Space complexity:\n0(26)\n\n# Code\n```\nclass Solution {\npublic:\n    string modifyString(string s) {\n        int n = s.length();\n        if(n==1){\n            if(s[0]==\'?\'){\n                return "a";\n            }\n            return s;\n        }\n        if(s[0]==\'?\'){\n            if(s[1]==\'a\'){\n                s[0]=\'b\';\n            }\n            else{\n                s[0]=\'a\';\n            }\n        }\n        for(int i = 1; i<= n-2;i++){\n            if(s[i]==\'?\'){\n                 vector<int> v(256,1);\n                  v[(int)s[i-1]]=0;\n                  v[(int)s[i+1]]=0;\n                  for(int k = 97 ; k<125;k++){\n                      if(v[k]){\n                          s[i]=char(k);\n                          break;\n                      }\n                  }\n                \n            }\n           \n        \n        }\n        if(s[n-1]==\'?\'){\n            if(s[n-2]==\'a\'){\n                s[n-1]=\'b\';\n            }\n            else{\n                s[n-1]=\'a\';\n            }\n        }\n        return s;\n    }\n};\n```
['C++']