Skip to content

Commit 3ac4711

Browse files
committed
Sync LeetCode submission - Fizz Buzz (c)
1 parent a97c241 commit 3ac4711

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

problems/fizz_buzz/solution.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
char** fizzBuzz(int n, int* returnSize) {
2+
*returnSize = n;
3+
char** arr = (char**) malloc(n * sizeof(char*));
4+
for (int i = 1; i <= n; ++i) {
5+
if (i % 15 == 0) {
6+
arr[i-1] = strdup("FizzBuzz");
7+
} else if (i % 5 == 0) {
8+
arr[i-1] = strdup("Buzz");
9+
} else if (i % 3 == 0) {
10+
arr[i-1] = strdup("Fizz");
11+
} else {
12+
char str[5];
13+
sprintf(str, "%d", i);
14+
arr[i-1] = strdup(str);
15+
}
16+
}
17+
return arr;
18+
}

0 commit comments

Comments
 (0)