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 ...
随机推荐
- HDU4004 二分答案
第一道二分答案...今天看了大牛的博客,突然发现有个叫“二分枚举答案”的方法好像很牛,于是便搜了些资料..发现并不是很难,可能是我了解的只是冰山一脚罢了...加油ACMer!!!! #include& ...
- IIS发布web应用程序之再折腾
最近几个月发布程序比较多,遇到了各种IIS发布web程序后无法访问的问题.原以为对各种问题都已经摸的差不多了,但今天又为一问题折腾了大半天.具体过程祥记如下: 在server2008 R2 64位系统 ...
- java swing+socket实现多人聊天程序
swing+socket实现多人聊天程序 1.准备工作 先看效果: 客户端项目结构图: 服务端项目结构图: 2.运行原理 服务端 先开一个线程serverListerner,线程中开启一个Server ...
- JS防抖动
这道题目经常与事件触发器同时存在,为了考察面试者在一些具体业务流程上(信息流,搜索框输入查询)等,能否综合的考虑实现思路. 题目:在某些信息列表中一般采用瀑布流,滚动一屏时加载相应的数据,请思考如何避 ...
- mysql load date to Hbase
一.mysql迁移数据进hbase需要配置好配置文件 用sqoop 命令进行迁移 二. 配置文件内容: import--connectjdbc:mysql://172.18.32.99:3306/te ...
- hive作业的优化策略
Mapreduce自身的特点: 1.IO和网络负载大:优化策略:减少IO和网络负载. 2.内存负载不大.优化策略:增大内存使用率: 3.CPU负载不大.优化策略:增大CPU使用率: (hive的优化应 ...
- 使用 windows 批处理指令(BAT文件)进行文件删除、复制操作
以下是做文件删除和复制的批处理指令 ::替换文件需要添加 /y 参数才能直接替换.不然会出现提示是否替换. ::复制Axis2Implementation和WebServices编译后的文件到tomc ...
- 【html、CSS、javascript-5】css应用场景补充
一.CSS全局应用 父标签div下包含两个子标签div,当子标签dvi全部向左float,此时父标签设置的背景色是不显示的 <!DOCTYPE html> <html lang=&q ...
- Iterm2 快捷键介绍
Mac 原来自带的终端工具 Terminal 不好用是出了名的,虽然最近几个版本苹果稍微做了些优化,功能上,可用性方面增强不少,无奈有个更好用的 Iterm2 摆在那,基本上也就没有多少出场机会了 I ...
- 读书笔记--Head First JQuery目录
1.JQuery入门 2.选择器与方法 3.JQuery事件与函数 4.JQuery Web页面管理 5.JQuery效果与动画 6.JQuery与JavaScript 7.定制函数停工定制效果 8. ...