📅  最后修改于: 2023-12-03 15:09:20.943000             🧑  作者: Mango
给定一个字符串s和一个整数k,求字典序最大的子序列,满足子序列中的每个字符都至少出现k次。
输入:s = "ababbc", k = 2
输出:"babbc"
输入:s = "ccaaaacc", k = 2
输出:"ccaaaacc"
def max_substring(s, k):
counts = {}
for c in s:
counts[c] = counts.get(c, 0) + 1
for c in counts:
if counts[c] < k:
sub_strs = s.split(c)
return max([max_substring(sub_str, k) for sub_str in sub_strs], key=len)
return s