题解 | #长度为 K 的重复字符子串#

长度为 K 的重复字符子串

https://www.nowcoder.com/practice/eced9a8a4b6c42b79c95ae5625e1d5fd

#include <unordered_map>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @param k int整型 
     * @return int整型
     */
    //
    bool numcount(string s1){
        unordered_map<char,int>counts;
        for(int i=0;i<s1.size();i++){
            counts[s1[i]]+=1;
        }
        for(int i=0;i<s1.size();i++){
            if(counts[s1[i]]>=2){
                return true;
            }
        }
        return false;
    } 
    int numKLenSubstrRepeats(string s, int k) {
        // write code here
        int count=0;
        for(int i=0;i<=s.size()-k;i++){
            string x=s.substr(i,k);
            if(numcount(x)){
                count+=1;
            }
        }
        return count;
    }
};













全部评论

相关推荐

Twilight_m...:还是不够贴近现实,中关村那块60平房子200万怎么可能拿的下来,交个首付还差不多
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
05-29 20:12
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务