[LeetCode] Find the Original Typed String I

3330. Find the Original Typed String I

Alice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a character being typed multiple times.

Although Alice tried to focus on her typing, she is aware that she may still have done this at most once.

You are given a string word, which represents the final output displayed on Alice’s screen.

Return the total number of possible original strings that Alice might have intended to type.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
int possibleStringCount(string word) {
int res = 0;
for(int i = 1; i < word.length(); i++) {
if(word[i] == word[i-1]) res++;
}
return res + 1;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/10/27/PS/LeetCode/find-the-original-typed-string-i/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.