substring 안의 문자는 최소 k개 있어야 함
언어: python3
class Solution:
def longestSubstring(self, s: str, k: int) -> int:
idx = 0
while idx < len(s) and s.count(s[idx]) >=k :
idx+=1
if idx == len(s):
return len(s)
left = self.longestSubstring(s[:idx],k)
right = self.longestSubstring(s[idx+1:],k)
return max(left,right)
답안 생각못해서 풀이 참고함
출처: https://kkminseok.github.io/posts/leetcode_Longest_Substring_with_At_Least_K_Repeating_Characters/