P17056 [GeeksforGeeks] Count the characters1821
普及-
题目描述

Given a string S. Count the characters that have ‘N’ number of occurrences. If a character appears consecutively it is counted as 1 occurrence.
Example 1:
Input:
S = "abc", N = 1
Output: 3
Explanation: 'a', 'b' and 'c' all have
1 occurrence.
​Example 2:
Input:
S = "geeksforgeeks", N = 2
Output: 4
Explanation: 'g', 'e', 'k' and 's' have
2 occurrences.
Your Task:
You don't need to read input or print anything. Your task is to complete the function getCount() which takes the string S and an integer N as inputs and returns the count of the characters that have exactly N occurrences in the string. Note that the consecutive occurrences of a character have to be counted as 1.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1<=|S|<=10^{5}
1<=N<=10^{3}

输入格式

见题面

输出格式

见题面

样例输入
S = "abc", N = 1
样例输出
3