[LeetCode]412. Fizz Buzz
来源:互联网 发布:双代号网络时间参数 编辑:程序博客网 时间:2024/05/09 14:24
412. Fizz Buzz
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”.
题目大意: 输出一个从1到n的字符串数组
能被3整除的用“Fizz”代替数字,能被5整除的用“Buzz”代替数字,
能被3和5整除的用“FizzBuzz”代替数字,其余均用数字表示。
列表内容
Example:n = 15,Return:[ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]
代码如下
C++class Solution {public: vector<string> fizzBuzz(int n) { vector<string> A; for(int i=1;i<=n;i++) { if(i%15 == 0) A.push_back("FizzBuzz"); else if(i%3 == 0) A.push_back("Fizz"); else if(i%5 == 0) A.push_back("Buzz"); else A.push_back(to_string(i)); } return A; }};
该题目读懂题意就能做。
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
- 412. Fizz Buzz [LeetCode]
- [leetcode]--412. Fizz Buzz
- Leetcode-412. Fizz Buzz
- [LeetCode]412. Fizz Buzz
- 10存储和文件结构
- 11索引与散列
- OC:对象、类、元类
- 14事务
- Java 加密与解密
- [LeetCode]412. Fizz Buzz
- JVM内幕:Java虚拟机详解
- Python中的类(上)
- ubuntu14.04 rabbitmq安装、线上部署及允许其他ip地址访问
- 淘宝app属于hybrid app吗?
- 【POJ】Symmetric Order
- 15并发控制
- PAT甲级1033. To Fill or Not to Fill (25)
- 15并发控制