All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0801_0900.s0830_positions_of_large_groups.Solution Maven / Gradle / Ivy

There is a newer version: 1.37
Show newest version
package g0801_0900.s0830_positions_of_large_groups;

// #Easy #String

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public List> largeGroupPositions(String s) {
        List> map = new ArrayList<>();
        int i = 0;
        while (i < s.length()) {
            int j = i;
            while (j < s.length() && s.charAt(j) == s.charAt(i)) {
                j++;
            }
            if ((j - 1) - i + 1 >= 3) {
                map.add(Arrays.asList(i, j - 1));
            }
            i = j;
        }
        return map;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy