Leetcode830.Positions of Large Groups较大分组的位置
在一个由小写字母构成的字符串 S 中,包含由一些连续的相同字符所构成的分组。
例如,在字符串 S = "abbxxxxzyy" 中,就含有 "a", "bb", "xxxx", "z" 和 "yy" 这样的一些分组。
我们称所有包含大于或等于三个连续字符的分组为较大分组。找到每一个较大分组的起始和终止位置。
最终结果按照字典顺序输出。
示例 1:
输入: "abbxxxxzzy" 输出: [[3,6]] 解释: "xxxx" 是一个起始于 3 且终止于 6 的较大分组。
示例 2:
输入: "abc" 输出: [] 解释: "a","b" 和 "c" 均不是符合要求的较大分组。
示例 3:
输入: "abcdddeeeeaabbbcd" 输出: [[3,5],[6,9],[12,14]]
说明: 1 <= S.length <= 1000
class Solution {
public:
vector<vector<int> > largeGroupPositions(string S) {
vector<vector<int> > res;
int len = S.size();
if(len == 0)
return res;
int start = 0;
int end = 0;
char flag = S[0];
for(int i = 1; i < len; i++)
{
end = i;
if(S[i] != flag)
{
end = i - 1;
if(end - start + 1 >= 3)
{
vector<int> temp;
temp.push_back(start);
temp.push_back(end);
res.push_back(temp);
}
flag = S[i];
start = i;
}
}
if(end - start + 1 >= 3)
{
vector<int> temp;
temp.push_back(start);
temp.push_back(end);
res.push_back(temp);
}
return res;
}
};
Leetcode830.Positions of Large Groups较大分组的位置的更多相关文章
- 830. Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- 830. Positions of Large Groups@python
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- 830. Positions of Large Groups - LeetCode
Question 830. Positions of Large Groups Solution 题目大意: 字符串按连续相同字符分组,超过3个就返回首字符和尾字符 思路 : 举例abcdddeeee ...
- 【Leetcode_easy】830. Positions of Large Groups
problem 830. Positions of Large Groups solution1: class Solution { public: vector<vector<int&g ...
- Positions of Large Groups
Positions of Large Groups In a string S of lowercase letters, these letters form consecutive groups ...
- Java实现 LeetCode 830 较大分组的位置(暴力模拟)
830. 较大分组的位置 在一个由小写字母构成的字符串 S 中,包含由一些连续的相同字符所构成的分组. 例如,在字符串 S = "abbxxxxzyy" 中,就含有 "a ...
- [Swift]LeetCode830. 较大分组的位置 | Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- C#LeetCode刷题之#830-较大分组的位置(Positions of Large Groups)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3750 访问. 在一个由小写字母构成的字符串 S 中,包含由一些连 ...
- [LeetCode] Positions of Large Groups 大群组的位置
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
随机推荐
- JavaWeb — Servlet(Server Applet)
Servlet(Server Applet) 全称Java Servlet,未有中文译文.是用Java编写的服务器端程序.其主要功能在于交互式地浏览和修改数据,生成动态Web内容. 狭义的Servle ...
- Redis学习笔记03-持久化
redis是一个内存型数据库,这就意味着,当主机重启或者宕机时,内存中的数据会被清空,redis可能会丢失数据.为了保存数据,实现数据持久化就必须要有一种机制,可以将redis数据库的数据保留在硬盘上 ...
- python-基础-基础知识-变量-选择-循环
1 基础知识 1.1 注释的分类 1.2 变量以及类型 变量定义 num1 = 100 #num1就是一个变量,就好一个小菜篮子 num2 = 87 #num2也是一个变量 result = num1 ...
- Python 字符串与二进制串的相互转换
def encode(s): return ' '.join([bin(ord(c)).replace('0b', '') for c in s]) def decode(s): return ''. ...
- Sublime keymap 个性修改
[ // 保存全部 {"keys": ["ctrl+alt+s"], "command": "save_all"}, / ...
- Hackerrank--XOR love (Math系列)
题目链接 Devendra loves the XOR operation very much which is denoted by ∧ sign in most of the programmin ...
- JavaScript如何实现字符串拼接操作
实际应用中,目标字符串的生成可能需要多个数据的拼接. 由于应用频繁,几乎是所有编程语言都必须掌握的操作,当然每种语言具有各自特点. 本文将通过代码实例详细介绍一下JavaScript如何实现字符串拼接 ...
- java swing调试时线程显示名字
一般有一个默认名字 但是具体运行到哪一个线程,需要猜 为了节约时间,提高效率 可以给线程写个中文名(因为默认就是英文,写中文,一眼就能挑出来) 以RTC定时器为例子 final TimerRtc ti ...
- springmvc报404错误No mapping found for HTTP request with URI [/mavenSpringmvc/requesttest] in DispatcherServlet with name 'spring'
问题404错误的原因有很多种 有这种,后边不带url的 这种一般就是没有进入到controller中 可以在toncat中看到信息 十一月 12, 2018 12:21:25 下午 org.sprin ...
- 常用命令5--文件搜索命令3-find
发现没有出来install.log.syslog ,find不能进行模糊搜索.要想模糊搜索,必须用通配符. 没有所有者的文件是垃圾文件.但是内核产生文件,在这两个文件夹里文件有可能没有所有者,很正常, ...