728x90
class Solution:
def partitionString(self, s: str) -> int:
substrings = []
sub = ''
for n in s:
if n in sub:
substrings.append(sub)
sub = n
else:
sub += n
substrings.append(sub)
return len(substrings)
https://leetcode.com/problems/optimal-partition-of-string
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 1941. Check if All Characters Have Equal Number of Occurrences (0) | 2024.03.05 |
---|---|
[Leetcode] 1748. Sum of Unique Elements (0) | 2024.03.04 |
[Leetcode] 2215. Find the Difference of Two Arrays (0) | 2024.03.03 |
[Leetcode] 2418. Sort the People (0) | 2024.03.02 |
[Leetcode] 1817. Finding the Users Active Minutes (0) | 2024.02.28 |