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 ...
随机推荐
- JEECMS 系统权限设计
1.用户校验. 登录校验主要围绕着用户后台登陆的url拦截 a.围绕着用户登录过程中设计到两张用户表 jc_user:存储着用户的基本信息 jo_user:存储着用户登录.注册.更新时间及用户密码信息 ...
- AppbarLayout的简单用法
在许多App中看到, toolbar有收缩和扩展的效果, 例如: appbar.gif 要实现这样的效果, 需要用到: CoordinatorLayout和AppbarLayout的配合, 以及实 ...
- python学习笔记3_数据载入、存储及文件格式
一.丛mysql数据库中读取数据 import pandas as pdimport pymysqlconn = pymysql.connect( host = '***', user = '***' ...
- Spring Cloud中Eureka开启密码认证
转载自 https://blog.csdn.net/u011499747/article/details/77410997 Eureka服务端配置 添加spring-boot-starter-secu ...
- PHP的cURL扩展库使用详解
在还没有接触curl的时候,相信大家在获取网页内容的时,使用得最多的一个函数就是:file_get_contents(),但是它的可控制性不够灵活,无法处理错误情况,对于各种复杂情况的采集更是显得有点 ...
- Chapter 1 线性表
Preface: 这部分主要是我考研之前的总结,留作以后用到时再翻出来看看.都是基础的知识点,望各(Da)位(Lao)不喜勿喷,欢迎指正. 适用人群:考研复习过一遍数据结构的,可以看看,查漏补缺(顺便 ...
- ajax 向后台数组解决;
$.ajax({ traditional: true//这个设置为true,data:{"steps":["qwe","asd"," ...
- 字符串匹配算法之kmp算法
kmp算法是一种效率非常高的字符串匹配算法,是由Knuth,Morris,Pratt共同提出的模式匹配算法,所以简称KMP算法 算法思想 在一个字符串中查找另一个字符串时,会遇到如下图的情况 我们通常 ...
- leetcode 57 Insert Interval & leetcode 1046 Last Stone Weight & leetcode 1047 Remove All Adjacent Duplicates in String & leetcode 56 Merge Interval
lc57 Insert Interval 仔细分析题目,发现我们只需要处理那些与插入interval重叠的interval即可,换句话说,那些end早于插入start以及start晚于插入end的in ...
- [Array]628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...