题目
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
视频讲解 YouTube<--欢迎点击订阅
视频讲解 bilibili<--欢迎点击订阅
-
Previous
LeetCode 2439 Minimize Maximum of Array (Python) -
Next
LeetCode 1020 Number of Enclaves (Python)
Related Issues not found
Please contact @MaxMing0 to initialize the comment