• Skip to primary navigation
  • Skip to content
  • Skip to footer
zhicheng xie's demo blog
  • Quick-Start Guide

    Your Name

    I am an amazing person.

    • Somewhere

    Replace All ?’s to Avoid Consecutive Repeating Characters

    less than 1 minute read

    <-E 1576> Replace All ?’s to Avoid Consecutive Repeating Characters

    class Solution {
    public:
        string modifyString(string s) {
            char f, b = ' ';
            for(int i=0;i<s.size();i++)
            {
                if(i != 0) b = s[i-1];
                f = s[i+1];
                if(s[i] == '?') s[i] = 'a';
                while(s[i] == b || s[i] == f) s[i]++;
            }
            return s;
        }
    };
    

    Tags: Algorithms, C++, Leetcode

    Updated: December 24, 2020

    Share on

    Twitter Facebook LinkedIn
    Previous Next

    You may also enjoy

    Decode Ways

    less than 1 minute read

    <-M 91> Decode Ways

    Word Break

    less than 1 minute read

    <-H 139> Word Break

    Distinct Subsequences

    less than 1 minute read

    <-H 115> Distinct Subsequences

    Edit Distance

    less than 1 minute read

    <-H 72> Edit Distance

    • Follow:
    • Feed
    © 2023 zhicheng xie's blog. Powered by Jekyll & Minimal Mistakes.