FizzBuzz Solution (C)

  • 0
    char** fizzBuzz(int n, int* returnSize) {
        char **pprtArry = (char**)malloc(n * sizeof(char*));
        *returnSize = n;
        for (int i=0; i<n; i++){
            if ((i+1)%15==0)
                pprtArry[i] = "FizzBuzz";
            else if((i+1)%3==0)
                pprtArry[i] = "Fizz";
            else if((i+1)%5==0)
                pprtArry[i] = "Buzz";
            else {
                pprtArry[i] = malloc(sizeof(int));
                sprintf(pprtArry[i],"%d", i+1);
        return pprtArry;

Log in to reply

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