

# @before-stub-for-debug-begin
from python3problem395 import *
from typing import *
# @before-stub-for-debug-end
#
# @lc app=leetcode.cn id=395 lang=python3
#
# [395] 至少有 K 个重复字符的最长子串
#
# https://leetcode.cn/problems/longest-substring-with-at-least-k-repeating-characters/description/
#
# algorithms
# Medium (52.47%)
# Likes: 689
# Dislikes: 0
# Total Accepted: 66.5K
# Total Submissions: 126.8K
# Testcase Example: '"aaabb"\n3'
#
# 给你一个字符串 s 和一个整数 k ,请你找出 s 中的最长子串, 要求该子串中的每一字符出现次数都不少于 k 。返回这一子串的长度。
#
#
#
# 示例 1:
#
#
# 输入:s = "aaabb", k = 3
# 输出:3
# 解释:最长子串为 "aaa" ,其中 'a' 重复了 3 次。
#
#
# 示例 2:
#
#
# 输入:s = "ababbc", k = 2
# 输出:5
# 解释:最长子串为 "ababb" ,其中 'a' 重复了 2 次, 'b' 重复了 3 次。
#
#
#
# 提示:
#
#
# 1
# s 仅由小写英文字母组成
# 1
#
#
#
# @lc code=start
class Solution:
def longestSubstring(self, s: str, k: int) -> int:
if s.__len__()<k:
return 0
if not s:
return 0
for c in set(s):
a=[]
if s.count(c)<k:
for t in s.split(c):
j=self.longestSubstring(t,k)
a.append(j)
return max(a)
return len(s)
# @lc code=end

889

被折叠的 条评论
为什么被折叠?



