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插入的用法。

最新文章

  1. 揭秘Windows10 UWP中的httpclient接口[2]
  2. java web学习总结(二十七) -------------------JSP标签介绍
  3. VS2015下如何用编译、调试程序。
  4. 隐式意图启动一个Activity
  5. .NET中Redis安装部署及使用方法简介附-&gt;开源Redis操作辅助类
  6. [.Net] 通过反射,给Enum加备注
  7. Ajax讲解
  8. Snagit 12 – 功能强的老牌截图软件
  9. [NOIP2014]解方程
  10. tomcat错误信息解决方案【严重:StandardServer.await: create[8005]
  11. struts2自定义拦截器与cookie整合实现用户免重复登入
  12. 在word中批量制作条形码
  13. ovirt node的安装简介
  14. 设计模式之单一职责原则(SRP)
  15. php逐行读取txt文件写入数组的方法
  16. jvm详情——4、分代垃圾回收详述
  17. Groovy 类名称赋值为变量使用(newInstance &amp; new)
  18. 实现java随机数Random的几招
  19. Java内存区域与各区域OOM
  20. spark SQL概述

热门文章

  1. 在C++中使用libuv时对回调的处理 (2)
  2. Java知识日常收集整理001Java获取变量的数据类型的实现方法
  3. Arduino 串行外设接口——W3Cschool
  4. 【原创】经验分享:一个小小emoji尽然牵扯出来这么多东西?
  5. CodeForces 79D 【Password】,洛谷P3943 【星空】
  6. Flink实例(五十): Operators(十)多流转换算子(五)coGroup 与union
  7. 西安交通大学c++[mooc]课后题12章(只有后两题)
  8. php中 ob_函数 例:ob_start();用法
  9. 热力图 vue 项目中使用热力图插件 “heatmap.js”(保姆式教程)
  10. 多测师讲解jmeter _基本介绍_(001)高级讲师肖sir