小白笔记------------------leetcode(412. Fizz Buzz )
来源:互联网 发布:华夏域名注册 编辑:程序博客网 时间:2024/06/03 21:39
Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.
Example:
n = 15,Return:[ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]
Subscribe to see which companies asked this question
注意二维字符串数组的malloc,先确定行数,然后为每行创造空间;注意二维字符串数组每行的赋值用*(p+i)的方式
/** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */char** fizzBuzz(int n, int* returnSize) { char **result; int i = 0, m =16; result =(char **)malloc( n*sizeof(char *) ); for(i = 0;i < n;i++ ) { result[i]=(char *)malloc( m * sizeof(char) ); } for(i=0;i<n;i++) { if((i+1)%15==0) *(result+i)="FizzBuzz"; else if((i+1)%3==0) *(result+i)="Fizz"; else if((i+1)%5==0) *(result+i)="Buzz"; else sprintf(*(result+i), "%d", i+1); } *returnSize =n; return result;}
0 0
- 小白笔记------------------leetcode(412. Fizz Buzz )
- LeetCode笔记:412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- [LeetCode]--412. Fizz Buzz
- LeetCode-412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- 【leetcode】412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- leetcode 412. Fizz Buzz
- leetcode 412. Fizz Buzz
- Leetcode 412.Fizz Buzz
- leetcode-412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- 【LeetCode】 412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- LeetCode--412. Fizz Buzz
- 412. Fizz Buzz [LeetCode]
- [leetcode]--412. Fizz Buzz
- 数据库之事务隔离性级别
- MPI—并行求和
- 如何准备阿里社招面试,顺谈Java程序员学习中各阶段的建议
- Nivo Slider Settings
- 专业期刊、学术名著网站
- 小白笔记------------------leetcode(412. Fizz Buzz )
- RMQ问题
- flex可自定义圆形加载进度条例子代码下载
- IDA反汇编学习- 修改.text段数据
- Pyhon 内存问题:提示和技巧
- 欢迎使用markdowm编辑器
- js中onclick传值问题
- 好的软件架构设计
- Building and Testing with Gradle笔记3——Ant and Gradle