-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpart.py
More file actions
29 lines (21 loc) · 911 Bytes
/
part.py
File metadata and controls
29 lines (21 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution(object):
def partitionLabels(self, S):
"""
:type S: str
:rtype: List[int]
"""
#
# 100 pass - Nice and a clear solution of stripping the string into selected and remaining and finding if strictly atmost one existence is satisfied - references from stefanpochmann
# Group present in the string
group = []
# Until the expiry of the string
while S:
# At Most One Character In a Group, so a multiple group should not contains the same character
i = 1
while set(S[:i]) & set(S[i:]):
i += 1
# Appending each group info
group.append(i)
# Rest of the string removing the corresponding group under consideration
S = S[i:]
return group