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. 局域网里别人如何访问我本地电脑里的nginx网站

    1.修改nginx.conf配置文件(我这里配了二级域名,所以我在二级域名配置文件修改) 把deny all全部改成autoindex on 2.关闭防火墙 3.重启nginx

  2. js函数 eql,equal,equalp

    function eql(obj, other) { if(stringp(obj) && stringp(other) && obj === other) retur ...

  3. Xshell设置网络设备自动登录

    使用Xshell登录网络设备时候需要手动输入用户名和密码 设置免输入用户名及密码 用户名 密码 再次登录就不需要手动输入用户名和密码了

  4. ROS基础

    在ROS中启动Gazebo物理仿真环境 roslaunch gazebo_ros empty_world.launch 打开后一片漆黑是以为gazebo需要从国外的网站上下载模型,国内网络不行,一直下 ...

  5. [No000011F]Python教程2/9-安装Python 及其解释器介绍

    因为Python是跨平台的,它可以运行在Windows.Mac和各种Linux/Unix系统上.在Windows上写Python程序,放到Linux上也是能够运行的. 要开始学习Python编程,首先 ...

  6. [No0000D8]rar合并到JPG.bat用图片隐藏文件

    echo off cls echo 请拖入jpg图像文件后回车: set /p imagefile= echo 请拖入rar文件后回车: set /p rarfile= copy /b %imagef ...

  7. CABasicAnimation 划线动画

    CGFloat animateDuration = ; UIBezierPath *bezierPath = [[UIBezierPath alloc] init]; CGPoint centerFr ...

  8. odoo10 入门

    一:入门准备 1:--xmlrpc-port=<端口> 命令选项充许我们将服务器实例的侦听端口从默认8069改为指定端口.这样可以在同一服务器上同时运行多个实例. 2:使用db-filte ...

  9. idea找不到import project

    一.首先File->close project 关完后,在界面你就可以看到import project

  10. tensorflow入门笔记(二) 滑动平均模型

    tensorflow提供的tf.train.ExponentialMovingAverage 类利用指数衰减维持变量的滑动平均. 当训练模型的时候,保持训练参数的滑动平均是非常有益的.评估时使用取平均 ...