LeetCode763. 划分字母区间
- 题目链接
- 代码
题目链接
https://leetcode.cn/problems/partition-labels/description/
代码
class Solution:
def partitionLabels(self, s: str) -> List[int]:
last_occ = {}
for i, ch in enumerate(s):
last_occ[ch] = i
result = []
start = 0
end = 0
for i, ch in enumerate(s):
end = max(end, last_occ[ch])
if end == i:
result.append(end - start + 1)
start = end + 1
return result