Skip to content

Commit bb9876a

Browse files
committed
Add C++ 19 20 Solutions
1 parent 7b33771 commit bb9876a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Problems/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
vector<int> partitionLabels(string s) {
4+
int n = s.length();
5+
vector<int> lastPos(26, 0);
6+
for (int i = 0; i < n; i++)
7+
{
8+
lastPos[s[i] - 'a'] = i;
9+
}
10+
11+
vector<int> ans;
12+
int startIndex = 0;
13+
while (startIndex < n)
14+
{
15+
int j = startIndex;
16+
int endIndex = lastPos[s[startIndex] - 'a'];
17+
while (j < endIndex)
18+
{
19+
if (lastPos[s[j] - 'a'] > endIndex) endIndex = lastPos[s[j] - 'a'];
20+
j++;
21+
}
22+
ans.push_back(endIndex - startIndex + 1);
23+
startIndex = endIndex + 1;
24+
}
25+
return ans;
26+
}
27+
};

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Solutions in various programming languages are provided. Enjoy it.
2424
16. 2023/02/07 [#2160 Minimum Sum of Four Digit Number After Splitting Digits](https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/16-Minimum-Sum-of-Four-Digit-Number-After-Splitting-Digits): Greedy
2525
17. 2023/02/08 [#1221 Split a String in Balanced Strings](https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/17-Split-a-String-in-Balanced-Strings): Greedy
2626
18. 2023/02/09 [#605 Can Place Flowers](https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/18-Can-Place-Flowers): Greedy
27-
27+
19. 2023/02/10 [#763 Partition Labels](): Greedy
2828

2929
## Weekly Contest
3030

0 commit comments

Comments
 (0)