题解 | #长度为 K 的重复字符子串#
长度为 K 的重复字符子串
https://www.nowcoder.com/practice/eced9a8a4b6c42b79c95ae5625e1d5fd
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param k int整型 * @return int整型 */ public int numKLenSubstrRepeats (String s, int k) { // write code here char[] str = s.toCharArray(); int i = 0; int count = 0; for (; i <= str.length - k; i++){ if (isEquality(str, i, k)){ count++; } } return count; } public boolean isEquality(char[] str, int i, int k){ int j = 0; int m = 0; for (j = i; j < str.length && j < i + k; j++){ for (m = j+1; m < str.length && m < i + k; m++){ if (str[j] == str[m]){ return true; } } } return false; } }