📂java
🔖算法
2021-01-07 10:56阅读: 72评论: 0推荐: 0

比较有意思的算法思路

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;
    }
复制代码

 

本文作者:zydjjcpdszylddpll

本文链接:https://www.cnblogs.com/jyfs/p/14245240.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   zydjjcpdszylddpll  阅读(72)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起