题解 | #长度为 K 的重复字符子串#
长度为 K 的重复字符子串
https://www.nowcoder.com/practice/eced9a8a4b6c42b79c95ae5625e1d5fd
思路清晰
#include <string.h> //判断字符串s从i到end位置有无重复字符串 int repeat(char* s,int i,int end) { for (; i < end; i++) { for (int j = i + 1; j < end; j++) { if (s[i] == s[j])return 1; } } return 0; } int numKLenSubstrRepeats(char* s, int k ) { // write code here int size = strlen(s); int res = 0; for (int i = 0; i < size - k + 1; i++) { res += repeat(s,i,i+k); } return res; }