Positions of Large Groups

In a string S of lowercase letters, these letters form consecutive groups of the same character.

For example, a string like S = "abbxxxxzyy" has the groups "a""bb""xxxx""z" and "yy".

Call a group large if it has 3 or more characters.  We would like the starting and ending positions of every large group.

The final answer should be in lexicographic order.

Example 1:

Input: "abbxxxxzzy"
Output: [[3,6]]
Explanation: "xxxx" is the single large group with starting 3 and ending positions 6.

Example 2:

Input: "abc"
Output: []
Explanation: We have "a","b" and "c" but no large group.

Example 3:

Input: "abcdddeeeeaabbbcd"
Output: [[3,5],[6,9],[12,14]]

Note:  1 <= S.length <= 1000

 1 vector<vector<int>> largeGroupPositions(string S) {
2 vector<vector<int>> res;
3 for(int i = 0; i < S.length(); ){
4 int j = i + 1;
5 while(S[j] == S[i]){
6 j++;
7 }
8 if(j-i >= 3){
9 res.push_back({i,j-1}); //二维vector可直接插入vector
10 }
11 i = j;
12 }
13 return res;
14
15 }

注意点:二维vector插入的用法。

Positions of Large Groups的更多相关文章

  1. 830. Positions of Large Groups@python

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  2. 【Leetcode_easy】830. Positions of Large Groups

    problem 830. Positions of Large Groups solution1: class Solution { public: vector<vector<int&g ...

  3. 830. Positions of Large Groups - LeetCode

    Question 830. Positions of Large Groups Solution 题目大意: 字符串按连续相同字符分组,超过3个就返回首字符和尾字符 思路 : 举例abcdddeeee ...

  4. [LeetCode] Positions of Large Groups 大群组的位置

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  5. [Swift]LeetCode830. 较大分组的位置 | Positions of Large Groups

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  6. [LeetCode&Python] Problem 830. Positions of Large Groups

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  7. 830. Positions of Large Groups

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  8. C#LeetCode刷题之#830-较大分组的位置(Positions of Large Groups)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3750 访问. 在一个由小写字母构成的字符串 S 中,包含由一些连 ...

  9. 【LeetCode】830. Positions of Large Groups 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. Java知识系统回顾整理01基础01第一个程序04创建Eclipse项目

    一.为Eclipse设置桌面快捷方式图标 二.双击桌面快捷方式打开Eclipse 三.选择工作区 使用在命令行Hello World中的项目目录e:\project 除了第一次启动eclipse的时候 ...

  2. JSON.stringify 的使用

    一.作用:这个函数的作用主要是为了序列化对象.就是把原来是对象的类型转换成字符串类型(json格式的String类型). 二.语法:JSON.stringify(value[, replacer][, ...

  3. c++缓冲区std::wstringbuf

    参考:http://www.cplusplus.com/reference/sstream/wstringbuf/ class <sstream> std::wstringbuf type ...

  4. MySQL 修改表中的字段,使其自增

    例如,我想使字段 id 自增. 1.查看表定义 mysql> DESC user; +----------+-------------+------+-----+---------+------ ...

  5. vue3.0版本安装

    如果安装过其他版本的vue的话先卸载 npm uninstall -g vue-cli //卸载指令 卸载不会影响以前项目的启动 然后安装 NPM安装: npm install -g @vue/cli ...

  6. Python之路——变量

    什么是变量 #变量即变化的量,核心是"变"与"量"二字,变即变化,量即衡量状态. 为什么要有变量 #程序执行的本质就是一系列状态的变化,变是程序执行的直接体现, ...

  7. Linux配置Docker

    Centos6.8 1.查看自己的内核 [1].uname [root@host79 ~]# uname -r 2.6.32-642.el6.x86_64 [2].查看CentOS版本信息 CentO ...

  8. URLEncoder.encode编码空格变+号

    今天调用rest接口的时候,使用URLEncoder编码将空格转为了+号,而rest接口方需要将空格转为%20,参照标准 之后用了不少在线的工具测试,有的将空格转为了+号,有的则是转为了%20.看了一 ...

  9. git 查看本地分支和切换本地分支的命令

    查看本地分支,和当前所在的分支 git branch -vv git checkout developer 切换到developer分支

  10. 【dos】wmic命令

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 磁盘 查看硬盘信息:wmic diskdrive 查看逻辑盘信息:wmic l ...