//获取list中相邻且相等的坐标组(开始下标与结束下标) public List<Interval> findEqualIntervals(List<String> strings){ List<Interval> intervals = new ArrayList<>(); int start = -1; for(int i = 0, i < strings.size(); i++ ){ if(i == 0 || !strings.get(i).equals(strings.get(i - 1))){ start = i; } else if (i == strings.size() -1 || !strings.get(i).equals(strings.get(i + 1))){ intervals.add(new Interval(start,i)) } } return intervals ; } @Data @AllArgConstructo @NoArgConstructor public class Interval{ private int start; private int end; }
获取list中相邻且相等的元素下标组(开始下标与结束下标)
最新推荐文章于 2024-09-03 09:32:52 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)