Fork me on GitHub

830. 较大分组的位置

class Solution {
   public List<List<Integer>> largeGroupPositions(String S) {
		List<List<Integer>> ls = new LinkedList<List<Integer>>();
		for (int i = 0; i < S.length() - 2; i++) {
			if (S.charAt(i) == S.charAt(i + 1) && S.charAt(i) == S.charAt(i + 2)) {
				char s = S.charAt(i);
				List<Integer> l = new LinkedList<Integer>();
				int a = i;
				int b = i;
				while (b<S.length()&&s == S.charAt(b)) {
					b++;
				}
				l.add(a);
				l.add(b-1);
				ls.add(l);
                i = b-1;
			}
		}
		return ls;

	}
}
posted @ 2019-08-04 14:58  cznczai  阅读(133)  评论(0编辑  收藏  举报