比较有意思的算法思路
1.较大分组的位置(相同字符串的下标集合长度>=3)
public static List<List<Integer>> largeGroupPositions(String s){ List<List<Integer>> res = new ArrayList<>(); //相同字符串左边边界 int left = 0; int length = s.length(); while (left < length) { //相同字符串的长度 int count = 1; //统计相同字符串的长度 while (left + count < length && s.charAt(left) == s.charAt(left + count)) { count++; } //如果长度大于等于3,就把他加入到res中 if (count > 2){ res.add(Arrays.asList(left, left + count - 1)); } //更新下一个字符串的左边边界 left = left + count; } return res; }

浙公网安备 33010602011771号