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. 设备像素,CSS像素,设备独立像素

    1.概念 设备像素(device pixel)简写DP 设备像素又称 **物理像素** ,是设备能控制显示的最小单位,我们可以把它看做显示器上的一个点.我们常说的 1920x1080像素分辨率就是用的 ...

  2. 【babel+小程序】记“编写babel插件”与“通过语法解析替换小程序路由表”的经历

    话不多说先上图,简要说明一下干了些什么事.图可能太模糊,可以点svg看看 背景 最近公司开展了小程序的业务,派我去负责这一块的业务,其中需要处理的一个问题是接入我们web开发的传统架构--模块化开发. ...

  3. H5使用Canvas绘图

    一.什么是Canvas Canvas 是H5的一部分,允许脚本语言动态渲染图像.Canvas 定义一个区域,可以由html属性定义该区域的宽高,javascript代码可以访问该区域,通过一整套完整的 ...

  4. python-模拟页面调度LRU算法

    [题目描述]所谓LRU算法,是指在发生缺页并且没有空闲主存块时,把最近最少使用的页面换出主存块,腾出地方来调入新页面. 问题描述:一进程获得n个主存块的使用权,对于给定的进程访问页面次序,问当采用LR ...

  5. mysql获取表的列名

    DESC test4 SHOW COLUMNS FROM test4 SELECT COLUMN_NAME  FROM information_schema.columns WHERE table_n ...

  6. java中instanceof是怎么用的, 干什么使的,举例!

    instanceof关键字 instanceof是java中固有的关键字, 就像main, public一样,用法:aa instanceof AA 就是问aa是不是AA的一个实例, 是的话,就返回真 ...

  7. Linux环境下Eclipse中快捷键不起作用

    在window->Preferences->general->keys中, 找到 content asist 修改下边值 Binding 改成 Alt+/ When 改为 Editi ...

  8. Android Studio项目导入方法+问题+解决办法

    我从一个大神的GitHub那下载了一个安全卫士软件 https://github.com/kotlindev/MobileSafe 1.下载到自己Android的项目文件夹,解压. 2.用AS打开这个 ...

  9. mysql绿色版安装以及遇到的问题

    下载mysql绿色版 放在如下文件夹  D:\javaSkill\mysql 修改my.ini文件内容: [mysql] default-character-set=utf8 [mysqld] bas ...

  10. Mybatis个人笔记

    Mybatis 简介 官网地址:mybatis – MyBatis 3 | 简介 MyBatis 是一款优秀的持久层框架,它支持自定义 SQL.存储过程以及高级映射.MyBatis 免除了几乎所有的 ...