/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
#define LEN 0xfffff
int check(char *s){
int ret = -1;
int cnt = 0;
int i=1;
while(s[i]) {
if(s[i] != s[i-1]) {
break;
}
cnt++;
i++;
}
if(cnt >= 2) return cnt+1;
return -1;
}
int** largeGroupPositions(char * s, int* returnSize, int** returnColumnSizes){
int **ret = (int **)malloc(sizeof(int*) * LEN);
int *rcs = (int *)malloc(sizeof(int) * LEN);
int index = 0, tmp;
int i, j;
i=0;
while(s[i]){
tmp = check(&s[i]);
if(tmp > 0){
ret[index] = (int *)malloc(sizeof(int) * 2);
ret[index][0] = i;
ret[index][1] = i+tmp-1;
rcs[index] = 2;
index++;
i += tmp;
continue;
}
i++;
}
*returnSize = index;
*(returnColumnSizes) = rcs;
return ret;
}
leetcode-830. 较大分组的位置-C语言
最新推荐文章于 2020-10-01 09:44:07 发布