Skip to content

Commit b02aceb

Browse files
authored
Create 763-Partition-Labels.py
1 parent 4c7209d commit b02aceb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

763-Partition-Labels.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def partitionLabels(self, S: str) -> List[int]:
3+
count = {}
4+
res = []
5+
i, length = 0, len(S)
6+
for j in range(length):
7+
c = S[j]
8+
count[c] = j
9+
10+
curLen = 0
11+
goal = 0
12+
while i < length:
13+
c = S[i]
14+
goal = max(goal, count[c])
15+
curLen += 1
16+
17+
if goal == i:
18+
res.append(curLen)
19+
curLen = 0
20+
i += 1
21+
return res

0 commit comments

Comments
 (0)