830. Positions of Large Groups(Leetcode每日一题-2021.01.05)
Problem
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”.
A group is identified by an interval [start, end], where start and end denote the start and end indices (inclusive) of the group. In the above example, “xxxx” has the interval [3,6].
A group is considered large if it has 3 or more characters.
Return the intervals of every large group sorted in increasing order by start index.
Constraints:
- 1 <= s.length <= 1000
- s contains lower-case English letters only.
Example1
Input: s = “abbxxxxzzy”
Output: [[3,6]]
Explanation: “xxxx” is the only large group with start index 3 and end index 6.
Example2
Input: s = “abc”
Output: []
Explanation: We have groups “a”, “b”, and “c”, none of which are large groups.
Example3
Input: s = “abcdddeeeeaabbbcd”
Output: [[3,5],[6,9],[12,14]]
Explanation: The large groups are “ddd”, “eeee”, and “bbb”.
Example4
Input: s = “aba”
Output: []
Solution
class Solution {public:vector<vector<int>> largeGroupPositions(string s) {vector<vector<int>> ret;if(s.empty())return ret;int cur_start = 0;int cur_end = 0;for(int i = 1;i<s.length();++i){if(i && s[i] == s[i-1]){++cur_end;}else{int len = cur_end - cur_start +1;vector<int> tmp;tmp.push_back(cur_start);tmp.push_back(cur_end);if(len >= 3){ret.push_back(tmp);}cur_start = i;cur_end = i;}}int len = cur_end - cur_start +1;vector<int> tmp;tmp.push_back(cur_start);tmp.push_back(cur_end);if(len >= 3){ret.push_back(tmp);}return ret;}
};
830. Positions of Large Groups(Leetcode每日一题-2021.01.05)相关推荐
- [leetcode每日一题2021/5/8]1723. 完成所有工作的最短时间
1723. 完成所有工作的最短时间 题目 思路 动态规划 状态转移方程 优化 求和打表 快速枚举每种选取情况jjj的子集ppp 代码 算法复杂度 题目来源于leetcode,解法和思路仅代表个人观点. ...
- LeetCode每日一题-2021/06/15-山脉数组的峰顶索引
山脉数组的封顶索引–java–二分法 思路: 这道题最容易想到的就是枚举每个数字,而要想将时间复杂度降为O(logN), 可以使用二分的思想(利用arr[0] < arr[1] < - a ...
- 208. Implement Trie (Prefix Tree)(Leetcode每日一题-2021.04.14)
Problem A trie (pronounced as "try") or prefix tree is a tree data structure used to effic ...
- LeetCode 每日一题 2021/9/27-2021/10/3
记录了初步解题思路 以及本地实现代码:并不一定为最优 也希望大家能一起探讨 一起进步 目录 9/27 639. 解码方法 II 9/28 437. 路径总和 III 9/29 517. 超级洗衣机 9 ...
- leetcode每日刷题计划-简单篇day8
leetcode每日刷题计划-简单篇day8 今天是纠结要不要新买手机的一天QAQ想了想还是算了吧,等自己赚钱买,加油 Num 70 爬楼梯 Climbing Stairs class Solutio ...
- Leetcode每日一题:171.excel-sheet-column-number(Excel表列序号)
思路:就是168题的反命题,进制的方式完美解决: Leetcode每日一题:168.excel-sheet-column-title(Excel表名称) class Solution {public: ...
- 【LeetCode每日一题】1723. 完成所有工作的最短时间
[LeetCode每日一题]1723. 完成所有工作的最短时间 [1] 1723. 完成所有工作的最短时间 [2] 473. 火柴拼正方形 [1] 1723. 完成所有工作的最短时间 题目: 给你一个 ...
- leetcode每日一题--雀巢原理;抽屉算法;Quorum机制;分布式应用
leetcode每日一题 539. 最小时间差 示例 1: 输入:timePoints = ["23:59","00:00"] 输出:1 示例 2: 输入:ti ...
- LeetCode每日一题——1812. 判断国际象棋棋盘中一个格子的颜色
LeetCode每日一题系列 题目:1812. 判断国际象棋棋盘中一个格子的颜色 难度:简单 文章目录 LeetCode每日一题系列 题目 示例 思路 题解 题目 给你一个坐标 coordinates ...
最新文章
- 核心算法缺位,人工智能发展面临“卡脖子”窘境
- Database之SQLSever:SQL命令实现四则运算、desc降序、like模糊查询、distinct去重、MAX/MIN/SUM/AVG/COUNT/GROUP/having等案例之详细攻略
- select下拉框赋值和取值
- 【转】c#数字图像处理(三)灰度直方图
- python中format函数用法简书_增强的格式化字符串format函数
- 小技巧来助阵 玩转Google Chrome(谷歌浏览器)
- python编程一球从100米_Python基础练习实例20(弹球问题)
- effective C++ 条款 11:在operator= 处理‘自我赋值’
- 2017.10.5 最短母串 思考记录
- 四川第七届 C Censor (字符串哈希)
- windows下MySQL 5.7+ 解压缩版安装配置方法
- php 读取数据库信息,php读取数据库信息的几种方法
- GJB150A湿热试验-高低温交变湿热试验标准检测报告
- 【课程·研】高级人工智能 | MOOC习题及课后作业:期末考试
- 在线编辑Word——插入图片、图形
- buildSrc使用,依赖统一管理
- 腾讯云+CentOS 7.2+python:搭建微信公众号后台入门教程
- SpringBoot整合模板FreeMarker篇
- 用链接法实现散列表构造和查找
- 微信小程序,后台数据返回的数据带有回车符,对文本进行回车符处理