题目描述
Given a binary string S and an integer K, the task is to count the number of substrings that contain exactly K ones.
Example 1:
Input : S = 10010, K = 1
Output : 9
Explanation: The 9 substrings containing
one 1 are, 1, 10, 100, 001, 01,
1, 10, 0010 and 010.
Example 2:
Input : S = 111, K = 2
Output : 2
Explanation: The 2 substrings containing
two 1 are 11, 11.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countOfSubstringWithKOnes() which takes the string S and an integer K as inputs and returns the count.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)
Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ K ≤ 10^{4}
输入格式
见题面
输出格式
见题面
样例输入
S = 10010, K = 1
样例输出
9