# leetcode Weekly Contest 67 -- 763. Partition Labels

Description

A string S of 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:

1. S will have length in range [1, 500].
2. S will 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;
}
};

• 本文已收录于以下专栏：

## LWC 67: 763. Partition Labels

LWC 67: 763. Partition Labels 传送门：763. Partition Labels Problem: A string S of lowercase lette...
• u014688145
• 2018年01月14日 15:38
• 336

## LeetCode Partition Labels 问题

• m0_37462976
• 2018年01月16日 13:47
• 42

## 763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as pos...
• zjucor
• 2018年01月14日 16:00
• 83

## 763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as pos...
• u012033124
• 2018年01月17日 00:06
• 18

## Partition Labels

https://leetcode.com/problems/partition-labels/description/ 题解： 题目的意思是输入一个字符串，将其尽可能地连续地分为多个字符串，且每...
• weixin_38997311
• 2018年01月27日 18:06
• 10

## 763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as pos...
• idwtwt
• 2018年01月23日 16:17
• 32

## 763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as pos...
• u013527178
• 2018年02月04日 13:13
• 7

## 763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as pos...
• Elegdawnce
• 2018年01月17日 12:55
• 69

## LeetCode | 763. Partition Labels 中等偏难贪心算法 把一个字符串划分为有独立字母的最多组的划分方法

Astring S of lowercase letters is given. We want to partition thisstring into as many parts as possi...
• u012737193
• 2018年01月18日 17:55
• 36

## leetCode练习（80）

• u010771890
• 2016年10月17日 09:02
• 220

举报原因： 您举报文章：leetcode Weekly Contest 67 -- 763. Partition Labels 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)