Skip to content

Commit b747ed6

Browse files
committed
add FizzBuzz
1 parent 047c913 commit b747ed6

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.DS_Store

12 KB
Binary file not shown.

FizzBuzz.c

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
char ** fizzBuzz(int n, int* returnSize)
2+
{
3+
*returnSize = n;
4+
char** answer;
5+
answer = malloc(n * sizeof(char*));
6+
for (int i = 1; i < n + 1; i++)
7+
{
8+
char* s;
9+
if (i % 15 == 0)
10+
{
11+
answer[i - 1] = strdup("FizzBuzz");
12+
}
13+
else if (i % 5 == 0)
14+
{
15+
answer[i - 1] = strdup("Buzz");
16+
}
17+
else if (i % 3 == 0)
18+
{
19+
answer[i - 1] = strdup("Fizz");
20+
}
21+
else
22+
{
23+
int length = snprintf(NULL, 0, "%d", i);
24+
char* i_str = malloc(length + 1);
25+
snprintf(i_str, length + 1, "%d", i);
26+
answer[i - 1] = i_str;
27+
}
28+
}
29+
return answer;
30+
}

LeetCode/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)