Skip to content

Commit d883a4a

Browse files
committed
Mar 30
1 parent f7c7823 commit d883a4a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def partitionLabels(self, s: str) -> list[int]:
3+
last = {ch: idx for idx, ch in enumerate(s)}
4+
result = [0]
5+
ptr = 0
6+
while ptr < len(s):
7+
end = last[s[ptr]]
8+
while ptr <= end:
9+
ch = s[ptr]
10+
end = max(end, last[ch])
11+
ptr += 1
12+
result.append(ptr)
13+
return [result[idx] - result[idx-1] for idx in range(1, len(result))]
14+
15+
16+
def main():
17+
s = 'ababcbacadefegdehijhklij'
18+
assert Solution().partitionLabels(s) == [9, 7, 8]
19+
20+
s = 'eccbbbbdec'
21+
assert Solution().partitionLabels(s) == [10]
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
| March 26 | [2033. Minimum Operations to Make a Uni-Value Grid](https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/) | Medium | Solved |
3333
| March 27 | [2780. Minimum Index of a Valid Split](https://leetcode.com/problems/minimum-index-of-a-valid-split/) | Medium | Unsolved |
3434
| March 28 | [2503. Maximum Number of Points From Grid Queries](https://leetcode.com/problems/maximum-number-of-points-from-grid-queries/) | Hard | Unsolved |
35-
| March 29 | []() | | |
36-
| March 30 | []() | | |
35+
| March 29 | [2818. Apply Operations to Maximize Score](https://leetcode.com/problems/apply-operations-to-maximize-score/) | Hard | Unsolved |
36+
| March 30 | [763. Partition Labels](https://leetcode.com/problems/partition-labels/) | Medium | Solved |
3737
| March 31 | []() | | |
3838

3939

4040
## Summary
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 6 | 6 | 0 |
44-
| Medium | 20 | 9 | 11 |
45-
| Hard | 2 | 0 | 2 |
44+
| Medium | 21 | 10 | 11 |
45+
| Hard | 3 | 0 | 3 |

0 commit comments

Comments
 (0)