题目描述
在一个由小写字母构成的字符串 s 中,包含由一些连续的相同字符所构成的分组。
例如,在字符串 s = "abbxxxxzyy" 中,就含有 "a", "bb", "xxxx", "z" 和 "yy" 这样的一些分组。
分组可以用区间 [start, end] 表示,其中 start 和 end 分别表示该分组的起始和终止位置的下标。上例中的 "xxxx" 分组用区间表示为 [3,6] 。
我们称所有包含大于或等于三个连续字符的分组为 较大分组 。
找到每一个 较大分组 的区间,按起始位置下标递增顺序排序后,返回结果。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/positions-of-large-groups
strs = str(input())
str_1 = ''
Lists = []
for i in range(len(strs)):
s = strs[i]
if str_1 == '':
str_1 += s
Index_start = i
Index_end = i
elif s in str_1:
str_1 += s
Index_end += 1
elif len(str_1) >= 3:
Lists.append([Index_start, Index_end])
str_1 = ''
str_1 += s
Index_start = i
Index_end = i
else:
str_1 = ''
str_1 += s
Index_start = i
Index_end = i
if Index_end - Index_start >= 2:
Lists.append([Index_start, Index_end])
print(Lists)