[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 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
- class Solution(object):
- def largeGroupPositions(self, S):
- """
- :type S: str
- :rtype: List[List[int]]
- """
- start=end=-1
- count=0
- ans=[]
- for i in range(len(S)):
- if count>0:
- if S[i]!=S[i-1]:
- if count>=3:
- end=i-1
- ans.append([start,end])
- start=i
- count=1
- else:
- start=i
- count=1
- else:
- count+=1
- else:
- count+=1
- start=i
- if count>=3:
- ans.append([start,len(S)-1])
- return ans
[LeetCode&Python] Problem 830. Positions of Large Groups的更多相关文章
- 【Leetcode_easy】830. Positions of Large Groups
problem 830. Positions of Large Groups solution1: class Solution { public: vector<vector<int&g ...
- 830. Positions of Large Groups - LeetCode
Question 830. Positions of Large Groups Solution 题目大意: 字符串按连续相同字符分组,超过3个就返回首字符和尾字符 思路 : 举例abcdddeeee ...
- 830. Positions of Large Groups@python
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- 【LeetCode】830. Positions of Large Groups 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 830. Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- Positions of Large Groups
Positions of Large Groups In a string S of lowercase letters, these letters form consecutive groups ...
- [LeetCode] Positions of Large Groups 大群组的位置
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- [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 ...
- C#LeetCode刷题之#830-较大分组的位置(Positions of Large Groups)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3750 访问. 在一个由小写字母构成的字符串 S 中,包含由一些连 ...
随机推荐
- Eclipse集成weblogic教程
1.在线安装插件 1.1安装Oracle Weblogic Servers Tools oeop是添加的软件仓库的名字,随便写主要是方便记. 仓库链接:http://www.oracle.com/te ...
- Redis在windows下的安装下载
1买个mac和台式电脑安装个Linux系统 2教程见:https://jingyan.baidu.com/article/0f5fb099045b056d8334ea97.html powerS ...
- python 转换代码格式
import os dirname="C:\\Users\\haier\\Desktop\\new" def walk(path): for item in os.listdir( ...
- zabbix3.4.7之Zabbix_Trigger_Function详解
Trigger函数 1.abschange 参数:直接忽略后边的参数 支持值类型:float.int.str.text.log 描述:返回最近获取到的值与之前值的差值的绝对值.对于字符串类型,0表示值 ...
- Mysql InnoDB三大特性-- 自适应hash index
Mysql InnoDB三大特性-- 自适应hash index
- linux生成SSH key
1. 检查SSH keys是否存在 ls -al ~/.ssh2. 生成新的ssh key 输入 ssh-keygen -t rsa -C your_email@example.com
- 理解JavaScript的运行
JavaScript可以运行在head和body标签中! HTML的脚本必须放在<script></script>标签中间! 浏览器会解释并执行位于script标签中的脚本! ...
- VS2010编译Unigine_2010源码
VS2010编译Unigine_2010源码[Debug版本] 1.Laucher工程属性改为控制台项目 2.Unigine工程编译时的Warnning LNK2019 a.属性--常规-目标文件名改 ...
- 二、求水仙花数,打印出100-999之间所有的"水仙花数"
所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身. 例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方 public c ...
- 使用keytool生成公钥、私钥、证书并且读取出来,使用私钥签名jar并验证(转)
参考链接:http://happyqing.iteye.com/blog/2139504 :https://blog.csdn.net/arjelarxfc/article/details/52461 ...