import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param s string字符串
     * @param k int整型
     * @return int整型
     */
    public int numKLenSubstrRepeats (String s, int k) {
        // write code here
        if (k > s.length() || k == 1) {
            return 0;
        }
        // 重复子串的数目
        int result = 0;
        // 双指针
        for (int i = 0, j = k; j <= s.length(); j ++) {
            // 截取字符串的长度
            String res = s.substring(i, j);
            // 判断是否存在重复的字符串,定一个hash记录字符出现的字数
            HashMap<Character, Integer> hashMap = new HashMap<>();
            for (int n = 0; n < res.length(); n++) {
                if (hashMap.containsKey(res.charAt(n))) {
                    result ++;
                    break;
                } else {
                    hashMap.put(res.charAt(n), 1);
                }
            }
            // 清空hash
            hashMap.clear();
            i ++;
        }
        return result;
    }
}