leetcode Weekly Contest 67 -- 763. Partition Labels

原创 2018年01月14日 12:21:39

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
  • u014688145
  • 2018年01月14日 15:38
  • 336

LeetCode Partition Labels 问题

问题描述: A string S of lowercase letters is given. We want to partition this string into as many p...
  • m0_37462976
  • 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
  • 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
  • u012033124
  • 2018年01月17日 00:06
  • 18

Partition Labels

https://leetcode.com/problems/partition-labels/description/ 题解: 题目的意思是输入一个字符串,将其尽可能地连续地分为多个字符串,且每...
  • weixin_38997311
  • 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
  • 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
  • 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
  • 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
  • u012737193
  • 2018年01月18日 17:55
  • 36

leetCode练习(80)

题目:Remove Duplicates from Sorted Array II           难度:medium 问题描述: Follow up for "Remove Duplica...
  • u010771890
  • u010771890
  • 2016年10月17日 09:02
  • 220
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:leetcode Weekly Contest 67 -- 763. Partition Labels
举报原因:
原因补充:

(最多只允许输入30个字)