3ms c solution simple to understand

• ``````/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/

char** fizzBuzz(int n, int* returnSize) {
*returnSize = n;
char buf[11];
char** re_p = (char**)malloc(sizeof(char*)*n);
int i = 0;
for(i=0;i<n;i++)
{
if(((i+1)%3==0)&&((i+1)%5==0))
{
sprintf(buf,"%s","FizzBuzz");
}else if((i+1)%3==0){
sprintf(buf,"%s","Fizz");
}else if((i+1)%5==0){
sprintf(buf,"%s","Buzz");
}else{
sprintf(buf,"%d",i+1);
}
re_p[i]=malloc(sizeof(buf));
memcpy(re_p[i],buf,strlen(buf)+1);
memset(buf,"",11);
}

return re_p;
}
``````

• returnsize is array size ,not the count of string.

• @ludongshalimin The size should be the same as n right?

• *returnSize = n;
What's this for?

• @supermangrifterlv There is a requirement that "Return an array of size *returnSize.". I think this variable is used by Leetcode to do test.

• @supermangrifterlv
Maybe the reason is that str is char **,
so LeetCode needs to test the result by returnSize,
using

``````for (int i=0;i<returnSize;i++)
{
printf ("%s\n",str[i]);
}
``````

• @lanjiann You can print *returnSize & you will see it's 0. Without setting it by yourself, you won't get Accepted. Very confused why Leetcode set it to 0. Any sense??

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.