(未做出) leetcode 763. 划分字母区间

it2025-11-07  15

题解

class Solution: def partitionLabels(self, S: str) -> List[int]: pos = [[-1,0] for _ in range(26)] for i,c in enumerate(S): pos[ord(c)-97]=[i,pos[ord(c)-97][1]+1] left=-1 maxPos=-1 result = [] for i,c in enumerate(S): if pos[ord(c)-97][0]>maxPos: maxPos=pos[ord(c)-97][0] pos[ord(c)-97][1]-=1 if pos[ord(c)-97][0]==i and pos[ord(c)-97][1]==0 and i==maxPos: print(c,pos[ord(c)-97]) result.append(i-left) left=i return result
最新回复(0)