题目
Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.
Return the minimum number of substrings in such a partition.
Note that each character should belong to exactly one substring in a partition.
解题思路
贪心,让每个字符串尽可能多包含字母的个数,如果出现重复的字母就进行分割
代码
class Solution:
def partitionString(self, s: str) -> int:
res, seen = 1, ""
for c in s:
if c in seen:
seen = c
res += 1
seen += c
return res