3330: Find-the-Original-Typed-String-I
Easy


table of contents

Just iterate through the array and check the previous letter; if it is the same, then you can just append one to the ans counter (which is preset to 1 initially).

code

class Solution {
public:
    int possibleStringCount(string word){
        int ans = 1;
        char c = word[0];
        for (int i = 1; i < word.size(); ++i) 
        {
            if (c != word[i]) {
                c = word[i];
            } else {
                ++ans;
            }
        }
        return ans;
    }
};

complexity