数组串联

解题思路

加个头,加个尾,然后正常从index = 1开始找问号,找到就看下前后是不是有相同的

正常替换

最后掐头去尾return

代码


class Solution 
{
  public:
    string modifyString(string s) 
    {
      string temp = "?" + s + "?";
      string result = "";
      for (size_t loop = 1; loop < temp.length() - 1; loop++)
      {
        if (temp.at(loop) == '?')
        {
          for (char looptimes = 'a'; looptimes <= 'z'; looptimes++)
          {
            if (temp.at(loop - 1) != looptimes && temp.at(loop + 1) != looptimes)
            {
              temp.at(loop) = looptimes;
            }
          }
        }
      }
      for (size_t loop = 1; loop < temp.length() - 1; loop++)
      {
        result += temp.at(loop);
      }
      return result;
    }
};

留下评论


通过 WordPress.com 设计一个这样的站点
从这里开始