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

For example, a string like S = "abbxxxxzyy" has the groups "a""bb""xxxx""z" and "yy".

Call a group large if it has 3 or more characters.  We would like the starting and ending positions of every large group.

The final answer should be in lexicographic order.

Example 1:

Input: "abbxxxxzzy"
Output: [[3,6]]
Explanation: "xxxx" is the single large group with starting 3 and ending positions 6.

Example 2:

Input: "abc"
Output: []
Explanation: We have "a","b" and "c" but no large group.

Example 3:

Input: "abcdddeeeeaabbbcd"
Output: [[3,5],[6,9],[12,14]]

Note:  1 <= S.length <= 1000

思路用两个pointers

Code

class Solution:
def largeGroupPositions(self, s):
l, r, lr, ans = 0, 0, len(s),[]
while r < lr:
if s[r] != s[l]:
if (r - l) >= 3:
ans.append([l, r-1])
l = r
elif r == lr -1 and r - l + 1 >= 3:
ans.append([l,r])
r += 1
return ans

[LeetCode] 830. Positions of Large Groups_Easy tag: Two Pointers的更多相关文章

  1. 830. Positions of Large Groups - LeetCode

    Question 830. Positions of Large Groups Solution 题目大意: 字符串按连续相同字符分组,超过3个就返回首字符和尾字符 思路 : 举例abcdddeeee ...

  2. 【Leetcode_easy】830. Positions of Large Groups

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

  3. 830. Positions of Large Groups@python

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

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

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

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

  6. 830. Positions of Large Groups

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

  7. [LeetCode] 827. Making A Large Island

    In a 2D grid of 0s and 1s, we change at most one 0 to a 1. After, what is the size of the largest is ...

  8. Positions of Large Groups

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

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

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

随机推荐

  1. TOP100summit2017:网易云通信与视频CTO赵加雨:外力推动下系统架构的4个变化趋势

      壹佰案例:很荣幸邀请到您成为第六届壹佰案例峰会架构专场的联席主席,您曾深度参与Cisco Jabber,Webex Meeting, Cisco Spark等多项分布式实时通信类产品的架构与研发, ...

  2. [No0000142]Outlook通过添加签名 自动添加邮件模板

    新建邮件->alt+F9切换域代码显示. 编写好模板后,全选复制到签名. 2018/05/7_加班申请_高亚斌 工号 姓名 开始时间 结束时间 工作事项 160227 高亚斌 2018/05/7 ...

  3. 微信小程序image组件中aspectFill和widthfix模式应用详解

    aspectFill 与 widthfix 都是保持宽高比不变 aspectFill 保持纵横比缩放图片,只保证图片的短边能完全显示出来.也就是说,图片通常只在水平或垂直方向是完整的,另一个方向将会发 ...

  4. mysql 超时时间

    小结: 1.mysql服务端主动关闭链接的秒数: MySQL :: MySQL 8.0 Reference Manual :: 5.1.8 Server System Variables https: ...

  5. Uniform Resource Name Server

    HTTP The Definitive Guide 按址标识 identify by address 按名标识 identify by name Domain Name Server Uniform ...

  6. 关于.htaccess的设置

    RewriteEngine On #设置是否开始rewrite RewriteBase / #设置开始匹配的目录,比如web程序放在/var/www/html/test下,则这个值要设置为" ...

  7. 理解Hbase和BigTable(转)

    add by zhj: 这篇文章写的通俗易懂,介绍了HBase最重要的几点特性. 英文原文:https://dzone.com/articles/understanding-hbase-and-big ...

  8. tomcat停止和启动脚本

    日常重启tomcat比较麻烦,所以写了2个脚本,在脚本后输入tomcat名称即可 启动或重启tomcat #!/bin/sh TOMCAT_HOME=/usr/java/$1 if [ ! -n &q ...

  9. NOIP2009靶形数独

    题目描述: 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向 Z 博士请教,Z 博士拿出了他最近发明的“ ...

  10. python下载youtube视频

    谷歌开源了一个新的数据集,BoundingBox,(网址在这里)这个数据集是经过人工标注的视频数据集,自然想将它尽快地运用在实际之中,那么首先需要将其下载下来:可以看到网址上给出的是csv文件,该文件 ...