Question

830. Positions of Large Groups

Solution

题目大意:

字符串按连续相同字符分组,超过3个就返回首字符和尾字符

思路 :

  1. 举例abcdddeeeeaabbbcd
  2. end start end-start
  3. a 0 0
  4. b 1 0,1 1-0=1
  5. c 2 1,2 2-1=1
  6. d 3 2,3 3-2=1
  7. d 4 3
  8. d 5 3
  9. e 6 3,6 6-3=3 3,5
  10. e 7 6
  11. e 8 6
  12. e 9 6
  13. a 10 6,10 10-6=4 6,9
  14. a 11 10
  15. b 12 10,12 12-10=2
  16. b 13 12
  17. b 14 12
  18. c 15 12,15 15-12=3 12,14
  19. d 16 13,14 16-15=1

Java实现:

  1. public List<List<Integer>> largeGroupPositions(String S) {
  2. List<List<Integer>> retList = new ArrayList<>();
  3. if (S.length() < 3) return retList;
  4. int startIdx = 0, endIdx = 0;
  5. for (int i = 1; i < S.length(); i++) {
  6. endIdx = i;
  7. if (S.charAt(i) != S.charAt(startIdx)) {
  8. if (endIdx - startIdx > 2) {
  9. retList.add(Arrays.asList(startIdx, endIdx - 1));
  10. }
  11. startIdx = i;
  12. }
  13. }
  14. if (endIdx - startIdx > 1) {
  15. retList.add(Arrays.asList(startIdx, endIdx));
  16. }
  17. return retList;
  18. }

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. spi详解

    来源:https://www.sohu.com/a/211324861_468626 1. SPI简介 SPI,是英语Serial Peripheral interface的缩写,顾名思义就是串行外围 ...

  2. CentOS7 Network Setting

    #display devices[root@localhost ~]# nmcli d #set ipv4 address[root@localhost ~]# nmcli c modify eth0 ...

  3. vue 相关问题整理

  4. Springcloud报错:java.lang.IllegalStateException: Service id not legal hostname (/a-service)

    今天在做springcloud链路追踪的时候,报错java.lang.IllegalStateException: Service id not legal hostname (/a-service) ...

  5. 脏数据清洗,pandas.apply()的应用

    原数据如下所示: IMAGETYPE count .?+? 1713 Jh.5? 100 .??U 38 .11.1 1 .13.1 1 .15.11 2 我需要对数据内的带有特殊符号,且第一个逗号 ...

  6. 阿里云-部署-服务-Docker

    目录 ♫ MusicPlayer Naiveboom - 比较安全 个人阿里云部署的小服务,欢迎使用,服务器资源有限,如果遇到卡顿还请谅解~ 索引: 在线音乐播放器 阅后即焚 ♫ MusicPlaye ...

  7. keytools命令生成证书

    平时开发中可以使用keytools命令生成证书,一般常用格式为: keytool -genkey -alias tzzxxt -keyalg RSA -keypass 123456 -validity ...

  8. 帝国CMS网站地图生成插件

    可以生成电脑端也可以生成手机端的地图XML. 安装方法: 这个帝国sitemap插件的安装跟其他插件的安装方式一样,介于可能有人不会安装帝国的插件,就写一下吧,以后你们如果碰到帝国插件也可以参考这个. ...

  9. SpringCloudAlibaba入门之Sentinel(SCA)

    微服务保护和熔断降级技术Sentinel 1.微服务调用存在问题 由于一个服务不可用,有可能会导致一连串的微服务跟着不可用[服务器支持的线程和并发数有限,请求一直阻塞,会导 致服务器资源耗尽,从而导致 ...

  10. 【Electron】Electron Icon 图标说明、及常见问题

    [Electron]Electron Icon 图标说明.及常见问题 其实各种打包模块都有相关的文档说明,相关链接如下: electron-builder:https://www.electron.b ...