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. SVN在idea中操作解析图

    进入的位置

  2. 让你熟知jquery见鬼去吧

    $是jquery最具代表的符号,当然php也是,但是二者不能同日而语;不得不说jquery的选择器是大家赞不绝口的,在它1.x版本中对ie兼容性是最好的,这要归功于$选择器; 现在呢,html5的降临 ...

  3. PAT B1014 福尔摩斯约会

    大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...

  4. 彻底理解synchronized

    1. synchronized简介 在学习知识前,我们先来看一个现象: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 public ...

  5. Bugku的exec执行绕过

    题目 思路 1. 打开网页显示403 2. 回去看题目有提示 3. 不用多说,网页访问. 4. 第一行说要传个参数ip,试一下get传参?ip=127.0.0.1 5. 试下 ① 算术运算符 & ...

  6. 12-factors

    12-factors 官方网址 The Twelve-Factor App 简介 如今,软件通常会作为一种服务来交付,它们被称为网络应用程序,或软件即服务(SaaS).12-Factor 为构建如下的 ...

  7. ajax - 终结篇jsonp,防抖节流

    今天是我们最后一天ajax的学习,这次学完总可以去vue了吧,我不信还有什么拦路石,先不说其他的先看看今天的内容. 1. 首先是同源策略,什么叫做同源? 如果两个页面的协议.域名.端口都相同的话,我们 ...

  8. uniapp-h5之canvans上文本的展示

    ctx.font = 'bold 14px arial';ctx.fillStyle = '#e9e6e6';ctx.fillText('长按图片保存到相册', (this.pwidth -250/e ...

  9. 数据库-mysql索引篇

    点赞再看,养成习惯,微信搜索「小大白日志」关注这个搬砖人. 文章不定期同步公众号,还有各种一线大厂面试原题.我的学习系列笔记. mysql的索引类型? mysql中有5种索引:普通索引.唯一索引.主键 ...

  10. 【学习笔记】CDQ分治(等待填坑)

    因为我对CDQ分治理解不深,所以这篇博客只是我现在的浅显理解有任何不对的,希望大佬指出. 首先就是CDQ分治适用的题型: (1)带修改,但修改互相独立 (2)必须允许离线 (3)解决数据结构的题,能把 ...