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:

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

Example 2:

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

Example 3:

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

Note:  1 <= S.length <= 1000

  1. class Solution(object):
  2. def largeGroupPositions(self, S):
  3. """
  4. :type S: str
  5. :rtype: List[List[int]]
  6. """
  7. start=end=-1
  8. count=0
  9. ans=[]
  10.  
  11. for i in range(len(S)):
  12. if count>0:
  13. if S[i]!=S[i-1]:
  14. if count>=3:
  15. end=i-1
  16. ans.append([start,end])
  17. start=i
  18. count=1
  19. else:
  20. start=i
  21. count=1
  22. else:
  23. count+=1
  24. else:
  25. count+=1
  26. start=i
  27. if count>=3:
  28. ans.append([start,len(S)-1])
  29. return ans

  

[LeetCode&Python] Problem 830. Positions of Large Groups的更多相关文章

  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 - LeetCode

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

  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. 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. Eclipse集成weblogic教程

    1.在线安装插件 1.1安装Oracle Weblogic Servers Tools oeop是添加的软件仓库的名字,随便写主要是方便记. 仓库链接:http://www.oracle.com/te ...

  2. Redis在windows下的安装下载

    1买个mac和台式电脑安装个Linux系统 2教程见:https://jingyan.baidu.com/article/0f5fb099045b056d8334ea97.html    powerS ...

  3. python 转换代码格式

    import os dirname="C:\\Users\\haier\\Desktop\\new" def walk(path): for item in os.listdir( ...

  4. zabbix3.4.7之Zabbix_Trigger_Function详解

    Trigger函数 1.abschange 参数:直接忽略后边的参数 支持值类型:float.int.str.text.log 描述:返回最近获取到的值与之前值的差值的绝对值.对于字符串类型,0表示值 ...

  5. Mysql InnoDB三大特性-- 自适应hash index

    Mysql InnoDB三大特性-- 自适应hash index

  6. linux生成SSH key

    1. 检查SSH keys是否存在 ls -al ~/.ssh2. 生成新的ssh key 输入 ssh-keygen -t rsa -C your_email@example.com

  7. 理解JavaScript的运行

    JavaScript可以运行在head和body标签中! HTML的脚本必须放在<script></script>标签中间! 浏览器会解释并执行位于script标签中的脚本! ...

  8. VS2010编译Unigine_2010源码

    VS2010编译Unigine_2010源码[Debug版本] 1.Laucher工程属性改为控制台项目 2.Unigine工程编译时的Warnning LNK2019 a.属性--常规-目标文件名改 ...

  9. 二、求水仙花数,打印出100-999之间所有的"水仙花数"

    所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身. 例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方 public c ...

  10. 使用keytool生成公钥、私钥、证书并且读取出来,使用私钥签名jar并验证(转)

    参考链接:http://happyqing.iteye.com/blog/2139504 :https://blog.csdn.net/arjelarxfc/article/details/52461 ...