【leetcode】较大分组的位置

 

int** largeGroupPositions(char * s, int* returnSize, int** returnColumnSizes){
    int len = strlen(s);
    int** arr = (int**)calloc(len/3,sizeof(int*));
    int i,j=0,pre=0;
    for (i=1; i<=len; i++)
    {
        if (s[i] != s[i-1]) 
        {
            if (i-pre >= 3)
            {
                int* row = (int*)calloc(2,sizeof(int*));
                row[0]=pre;
                row[1]=i-1;
                arr[j] = row;
                (*returnColumnSizes)[j++]=2;
            }
            pre = i;
        }
    }
    *returnSize = j;
    return arr;
}

 

posted @ 2020-09-12 10:20  温暖了寂寞  阅读(87)  评论(0编辑  收藏  举报