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. stm32CubeMX+keil5好用还是stm32CubeID好用

    cubemx是图形配置软件, 可以节省往常配置IO口的时间, cubemx主推hal库, 它是生成keil工程的工具 cubemx生成的工程可以用keilv5编程软件来编辑... 用Cube mx定义 ...

  2. 使用css实现任意大小,任意方向, 任意角度的箭头

    使用css实现任意大小,任意方向, 任意角度的箭头 网页开发中,经常会使用到 下拉箭头,右侧箭头 这样的箭头. 一般用css来实现: { display: inline-block; margin: ...

  3. Vue的computed(计算属性)使用实例之TodoList

    最近倒腾了一会vue,有点迷惑其中methods与computed这两个属性的区别,所以试着写了TodoList这个demo,(好土掩面逃~); 1. methods methods类似react中组 ...

  4. android 布局的android:padding 和android:margin的区别

    android:layout_marginLeft指该控件距离边父控件的边距, android:paddingLeft指该控件内部内容,如文本距离该控件的边距. 如: 当按钮分别设置以上两个属性时,得 ...

  5. 如何跨线程访问Winform中的UI元素

    如何跨线程访问Winform中的UI元素 假如制作一个Socket聊天应用程序,很可能会用到多线程: 例如为Receive方法开辟单独一个线程,例如为Receive方法开辟单独一个线程(后台运行的线程 ...

  6. Docker镜像构建之Dockerfile

    在 Docker 中构建镜像最常用的方式就是使用 Dockerfile.Dockerfile 是一个用来构建镜像的文本文件. 官方文档:https://docs.docker.com/engine/r ...

  7. activity-alias属性的使用

    activity-alias是Android里为了重复使用Activity而设计的.1. 含义和作用:         对于activity-alias标签,它有一个属性叫android:targen ...

  8. Java 请求转发和重定向的区别以及JavaWeb三大作用域

    三大作用域以及转发和重定向 学习总结 1. 转发和重定向 转发 重定向 转发和重定向的区别: 什么时候用转发什么时候用重定向 三大作用域 作用域类型 作用域方法 如何选择作用域 总结 学习总结 1. ...

  9. 深入研究const(es6特性)

    const  申明常量 var str = 'es6' console.log(window.str) // es6 属于顶层对象window const不属于顶层对象window const str ...

  10. location中的各个属性

    http://172.16.20.218:8080/m/MGU20201126001-001/index.html?username=admin&password=123#/write   浏 ...