leetcode Weekly Contest 67 -- 763. Partition Labels
2018-01-14 12:21
501 查看
Description
A string
Example 1:
Note:
A string
Sof lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
Example 1:
Input: S = "ababcbacadefegdehijhklij" Output: [9,7,8] Explanation: The partition is "ababcbaca", "defegde", "hijhklij". This is a partition so that each letter appears in at most one part. A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits S into less parts.
Note:
Swill have length in range
[1, 500].
Swill consist of lowercase letters (
'a'to
'z') only.
class Solution { public: vector<int> partitionLabels(string S) { int len = 0,m=0; vector<int>sum; map<char,int>mp; int i=0; while (i<S.length()) { len++; for (; i < len; i++) { if (!mp.count(S[i])) { mp[S[i]] = 0; for (int j = S.length() - 1; j >= i; j--) { if (S[i] == S[j]) { if (len <= j) len = j + 1; break; } } } } sum.push_back(len - m); m = len; } return sum; } };
相关文章推荐
- leetcode Weekly Contest 67 -- 765. Couples Holding Hands
- LeetCode Weekly Contest 31解题思路
- LeetCode Weekly Contest 51
- LeetCode Weekly Contest 52 Repeated String Match(string)
- LeetCode Weekly Contest 74 793. Preimage Size of Factorial Zeroes Function【二分】
- LeetCode Weekly Contest 23 之 541. Reverse String II
- LeetCode Weekly Contest 8
- LeetCode Weekly Contest 42解题思路
- LeetCode Weekly Contest 35解题思路
- LeetCode Weekly Contest 64 - 752. Open the Lock【BFS + string】
- LeetCode Weekly Contest 13-HammingDistance【易】
- LeetCode Weekly Contest 8 第八周周赛
- LeetCode Weekly Contest 30解题思路
- LeetCode Weekly Contest 43【总结】
- LeetCode Weekly Contest 24 之 538.Convert BST to Greater Tree
- LeetCode Weekly Contest 24 之 542.01 Matrix
- LeetCode 660 Remove 9 (LeetCode Weekly Contest 45)
- LeetCode Weekly Contest 38解题思路
- LeetCode Weekly Contest 46解题思路
- LeetCode Weekly Contest 47解题思路