830. Positions of Large Groups - LeetCode
Question
830. Positions of Large Groups

Solution
题目大意:
字符串按连续相同字符分组,超过3个就返回首字符和尾字符
思路 :
举例abcdddeeeeaabbbcd
end start end-start
a 0 0
b 1 0,1 1-0=1
c 2 1,2 2-1=1
d 3 2,3 3-2=1
d 4 3
d 5 3
e 6 3,6 6-3=3 3,5
e 7 6
e 8 6
e 9 6
a 10 6,10 10-6=4 6,9
a 11 10
b 12 10,12 12-10=2
b 13 12
b 14 12
c 15 12,15 15-12=3 12,14
d 16 13,14 16-15=1
Java实现:
public List<List<Integer>> largeGroupPositions(String S) {
List<List<Integer>> retList = new ArrayList<>();
if (S.length() < 3) return retList;
int startIdx = 0, endIdx = 0;
for (int i = 1; i < S.length(); i++) {
endIdx = i;
if (S.charAt(i) != S.charAt(startIdx)) {
if (endIdx - startIdx > 2) {
retList.add(Arrays.asList(startIdx, endIdx - 1));
}
startIdx = i;
}
}
if (endIdx - startIdx > 1) {
retList.add(Arrays.asList(startIdx, endIdx));
}
return retList;
}
830. Positions of Large Groups - LeetCode的更多相关文章
- 【Leetcode_easy】830. Positions of Large Groups
problem 830. Positions of Large Groups solution1: class Solution { public: vector<vector<int&g ...
- 830. Positions of Large Groups@python
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- 【LeetCode】830. Positions of Large Groups 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [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 ...
- 830. Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- Positions of Large Groups
Positions of Large Groups In a string S of lowercase letters, these letters form consecutive groups ...
- [LeetCode] Positions of Large Groups 大群组的位置
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- [LeetCode] 830. Positions of Large Groups_Easy tag: Two Pointers
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 中,包含由一些连 ...
随机推荐
- css 垂直居中方法汇总
查看原文可以有更好的排版效果哦 前言 居中是平时工作中的最常见的一种需求,各种图片居中或者各种弹窗,水平居中还好,特别是垂直居中,很多初学者表示太难写了,现在列举一些常用的方法. 实战 这里只讲述cs ...
- 移动端城市定位,城市区域代码adcode
使用高德定位API : AMap.Map('iCenter') AMap.CitySearch() 先在高德开放平台注册申请定位权限的key. 网站:高德开放平台 在需要定位的页面引入有定位key的s ...
- Java 多选框的全选、多选、反选(JQuery 实现)
jQuery 实现全选.多选.反选 学习内容: 需求 总结: 学习内容: 需求 jQuery 实现全选.多选.反选 实现代码 <!DOCTYPE html> <html lang=& ...
- JS 实现权限列表移动
JS 实现列表移动 学习内容: 需求 总结: 学习内容: 需求 用 JS 实现列表移动 实现代码 <html> <head> <meta http-equiv=" ...
- hibernate 联合主键 composite-id
如果表使用联合主键(一个表有两个以上的主键),你可以映射类的多个属性为标识符属性.如:<composite-id>元素接受<key-property> 属性映射(单表映射)和& ...
- Linux_连接工具_SecureCRT的使用教程
什么是SecureCRT? SecureCRT是一款支持 SSH2.SSH1.Telnet.Telnet/SSH.Relogin.Serial.TAPI.RAW 等协议的终端仿真程序,最吸引我的是,S ...
- 入行数字IC验证的一些建议
0x00 首先,推荐你看两本书,<"胡"说IC菜鸟工程师完美进阶>(pdf版本就行)本书介绍整个流程都有哪些岗位,充分了解IC行业的职业发展方向.<SoC设计方法 ...
- SpringMVC的数据响应-回写数据
1.直接返回字符串 其他具体代码请访问chilianjie @RequestMapping("/report5") public String save5(HttpServletR ...
- 在oracle控制台当你输入错误的时候,还不能删除,回退的解决方法
对于回退出现^H解决方法 oracle@prd:/home/oracle$sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on ...
- maven打包jar到本地仓库
1.执行如下命令 mvn install:install-file -Dfile=guava-28.2-jre.jar -DgroupId=com.google.guava -DartifactId= ...