/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* partitionLabels(char * s, int* returnSize){
int *result = (int *)malloc(sizeof(int) * strlen(s));
*returnSize = 0;
int i;
int rightIndex = -1;
for(i = 0; i<strlen(s); ++i)
{
int j;
for(j = strlen(s)-1; j>i; j--)
{
if(s[j] == s[i]) break;
}
if(j > rightIndex) rightIndex = j;
if(i == rightIndex)
{
if((*returnSize) == 0) result[(*returnSize)] = rightIndex + 1;
else
{
int k;
for(k=0; k<(*returnSize); ++k)
{
rightIndex -= result[k];
}
result[(*returnSize)] = rightIndex + 1;
}
(*returnSize)++;
rightIndex = -1;
}
}
return result;
}