Skip to content

Commit 08160cf

Browse files
committed
leetcode
1 parent 03e7893 commit 08160cf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
vector<int> partitionLabels(string S) {
4+
map<char, int> my_map;
5+
for (int i = 0; i < S.length(); i++)
6+
my_map[S[i]] = i;
7+
8+
vector<int> partitions;
9+
10+
int max_ = 0;
11+
int i = 0;
12+
int startPartition = 0;
13+
14+
while (i < S.length())
15+
{
16+
max_ = max_ > my_map[S[i]] ? max_ : my_map[S[i]];
17+
18+
if (max_ == i)
19+
{
20+
partitions.push_back(i + 1 - startPartition);
21+
startPartition = i + 1;
22+
}
23+
24+
i++;
25+
}
26+
return partitions;
27+
}
28+
};

0 commit comments

Comments
 (0)