21.1.5 leetcode830
题目链接:https://leetcode-cn.com/problems/positions-of-large-groups/
简单题,不多说。
Arrays.asList()的作用是将数组转化为List
class Solution { public List<List<Integer>> largeGroupPositions(String s) { List<List<Integer>> ans = new ArrayList<List<Integer>>(); int len = s.length(); int num = 1; for(int i=0;i<len;i++){ if(i==len-1 || s.charAt(i)!=s.charAt(i+1)){ if(num>=3){ ans.add(Arrays.asList(i-num+1,i)); } num=1; } else num++; } return ans; } }