分治法。

public class Solution
{
private int LongestSubstringSub(string s, int k, int start, int end)
{
if (start > end)
{
return ;
}
int[] count = new int[];
for (int i = start; i <= end; i++)
{
count[s[i] - 'a']++;
} for (int i = ; i < ; i++)
{
if (count[i] > && count[i] < k)
{
var pos = s.IndexOf((char)(i + 'a'), start);
return Math.Max(LongestSubstringSub(s, k, start, pos - ), LongestSubstringSub(s, k, pos + , end));
}
} return end - start + ;
} public int LongestSubstring(string s, int k)
{
return LongestSubstringSub(s, k, , s.Length - );
}
}

leetcode395的更多相关文章

  1. [Swift]LeetCode395. 至少有K个重复字符的最长子串 | Longest Substring with At Least K Repeating Characters

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  2. leetcode395 Longest Substring with At Least K Repeating Characters

    思路: 尺取法. 循环i:1~26,分别计算恰好包含i种字母并且每种字母出现的次数大于等于k个的最长子串长度. 没法直接使用尺取法,因为不满足区间单调性,但是使用如上的方法却是可以的,因为子串中包含的 ...

随机推荐

  1. hdu2516斐波那契博弈

    刚开始想用sg函数做,想了半天没一点思路啊. 原来这是一个新题型,斐波那契博弈 斐波那契博弈模型:有一堆个数为 n 的石子,游戏双方轮流取石子,满足:1. 先手不能在第一次把所有的石子取完:2. 之后 ...

  2. 校验基于EO的VO中的字段是否发生变化

    I have a table region and there are multiple records fetching from a Entity based VO. Now I have upd ...

  3. 关于 XML 头声明和standalone 的解释

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <roo ...

  4. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  5. 数据库链接池 durid 的配置参数详解

    这里我主要介绍druid 比较重要的参数解释,不做druid的使用介绍,druid虽然功能强大,但是如果对配置参数理解不到位,性能非但不能达到很优,而且会出现很多异常,所以使用druid之前一定要清楚 ...

  6. Sublime 中文标题乱码

    ---title:Sublime 中文标题乱码--- #markdown语法(非Github Flavored) #解决办法: 在用户设置里添加一项,强制不根据 dpi 缩放dpi_scale: 1. ...

  7. translate函数

    translate函数: select translate('ab23cd1', '.0123456789' || 'ab23cd1', '.0123456789') from dual 截图:

  8. websocket 缺点

    当时用 python 做的服务器,后来回去想再工作项目上用,但新的技术升级,随之而来还是要解决很多非技术问题, 服务器带宽,并发服务器性能方方面面考虑之后还是没有用上,十分可惜, 一个新的技术推动,尤 ...

  9. Hive之 hive-1.2.1 + hadoop 2.7.4 集群安装

    一. 相关概念 Hive Metastore有三种配置方式,分别是: Embedded Metastore Database (Derby) 内嵌模式Local Metastore Server 本地 ...

  10. curl查询公网出口IP

    liuzhizhi@lzz-rmbp|logs # curl ipinfo.io { "ip": "114.110.1.38", "hostname& ...