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的更多相关文章

  1. 【Leetcode_easy】830. Positions of Large Groups

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

  2. 830. Positions of Large Groups@python

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

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

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

  4. [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 ...

  5. 830. Positions of Large Groups

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

  6. Positions of Large Groups

    Positions of Large Groups In a string S of lowercase letters, these letters form consecutive groups ...

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

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

  8. [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 ...

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

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

随机推荐

  1. Django ElasticSearch Ionic 打造 GIS 移动应用 —— 架构设计

    搜索引擎是个好东西,GIS也是个好东西.当前还有Django和Ionic.最后效果图 构架设计 对我们的需求进行简要的思考后,设计出了下面的一些简单的架构. GIS架构说明 -- 服务端 简单说明: ...

  2. C#编写一个计算器

    编写一个计算器,练习在窗体上添加控件.调整控件的布局,设置或修改控件属性,编写事件处理程序的方法. 代码: using System; using System.Collections.Generic ...

  3. 【Android开发】【布局】 仿QQ的UI

    Demo地址

  4. ubantu系统之 在桌面添加应用快捷方式

    1. 首先在终端使用命令:sudo nautilus 这个命令会让你用root权限打开文件管理器,输入这个命令然后输入密码确认之后会弹出一个目录窗口;2. 然后我们就要找到目录:/usr/share/ ...

  5. 关于mysql使用utf8编码在cmd窗口无法添加中文数据的问题以及解决 方法二

    如果非要用cmd窗口的话,那么可以加这句话,set names gbk:

  6. c++对于c的拓展_引用的本质是指针常量

    本质:c++底层实现的指针常量(Type & ref =val; // Type *const ref =&val)

  7. Struts2-拦截器原理

    拦截器原理包含Aop思想和责任链模式 1.Aop思想 aop是面向切面编程,有基本功能,扩展功能,不通过修改源代码方式扩展功能.(动态代理) 2.责任链模式,Java有23种设计模式,责任链模式是其中 ...

  8. python关于变量介绍

    python变量 一.变量分为两种解释 1.随时可以变化的量 称之为变量 (变化多端嘛) 2.不会被变化的量 称之为常量 (常常不动嘛) #我们学习的python中没有真正定义的常量 #只有在绑定一个 ...

  9. 在线操作word和在线预览查找的资料记录

    在线操作word和在线预览查找的资料记录 在线操作word查找的资料记录 富文本操作 http://fex.baidu.com/ueditor/ 控件类 通过 js 调用控件操作 word 文档 1. ...

  10. JVM虚拟机类加载机制(一)

    类从被加载到虚拟机内存中开始,到卸载出内存截止,整个生命周期包括:加载.验证.准备.解析,初始化.使用.卸载七个阶段.其中验证.准备.解析三个部分统称为连接. 类初始化情况: 遇到new.getsta ...