From 9c2e4d85fc683fe1276a8b8d55b9289751ebf667 Mon Sep 17 00:00:00 2001 From: Qiming Xu <458173774@qq.com> Date: Sat, 13 Jan 2024 00:30:54 +0000 Subject: [PATCH] leetcode: finished #395 --- content/leetcode/2024/1.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/content/leetcode/2024/1.md b/content/leetcode/2024/1.md index c5f151f6..7e293ab6 100644 --- a/content/leetcode/2024/1.md +++ b/content/leetcode/2024/1.md @@ -3,6 +3,30 @@ title: 2024.1 draft: false --- +# 2024.1.13 + +```python +# +# @lc app=leetcode.cn id=395 lang=python3 +# +# [395] 至少有 K 个重复字符的最长子串 +# + + +# @lc code=start +class Solution: + def longestSubstring(self, s: str, k: int) -> int: + if len(s) < k: + return 0 + for c in set(s): + if s.count(c) < k: + return max(self.longestSubstring(t, k) for t in s.split(c)) + return len(s) + + +# @lc code=end +``` + # 2024.1.12 ```python