描述
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" |
Example 2:
1 | Input: "abc" |
Example 3:
1 | Input: "abcdddeeeeaabbbcd" |
Note: 1 <= S.length <= 1000
分析
一前一后双指针,一次遍历即可。
解决方案1(Java)
1 | class Solution { |