LeetCode
来源:互联网 发布:diff linux命令2c2 编辑:程序博客网 时间:2024/06/06 12:51
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"]
额,是3的倍数就输出 Fizz,是5的倍数就输出Buzz,是15的倍数就输出FizzBuzz,否则输出数字本身。
class Solution {public: vector<string> fizzBuzz(int n) { vector<string> ans(n); for (int i = 1; i <= n; ++i) { if (i % 3 == 0) ans[i-1] = "Fizz"; if (i % 5 == 0) ans[i-1] += "Buzz"; if (i % 3 && i % 5) ans[i-1] = to_string(i); } return ans; }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- [转载] linux proc maps文件分析
- 这是一篇用测试MetaAPI的测试内容2
- 部署docker registry
- 软件测试黑马工程师--liunx操作系统常见命令
- Springboot项目开发总结
- LeetCode
- How to transform our data into TFRecord(怎样将自己的图片数据转换成TF的格式)
- 006_JavaScript标识符
- 关于posix_memalign( )函数的坑
- TestNG参数化之@Parameters传参
- Linux下 GB2312和UTF8转换接口
- Django启动错误
- Ubuntu文件批量解压
- 【集训】jzoj 2017.8.10 noip模拟赛A 总结