412.fizz-buzz
Statement
Metadata
- Link: Fizz Buzz
- Difficulty: Easy
- Tag: 数学字符串模拟
给你一个整数 n ,找出从 1 到 n 各个整数的 Fizz Buzz 表示,并用字符串数组 answer(下标从 1 开始)返回结果,其中:
- answer[i] == "FizzBuzz"如果- i同时是- 3和- 5的倍数。
- answer[i] == "Fizz"如果- i是- 3的倍数。
- answer[i] == "Buzz"如果- i是- 5的倍数。
- answer[i] == i(以字符串形式)如果上述条件全不满足。
示例 1:
输入:n = 3
输出:["1","2","Fizz"]
示例 2:
输入:n = 5
输出:["1","2","Fizz","4","Buzz"]
示例 3:
输入:n = 15
输出:["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
提示:
- 1 <= n <= 104
Metadata
- Link: Fizz Buzz
- Difficulty: Easy
- Tag: MathStringSimulation
Given an integer n, return a string array answer (1-indexed) where:
- answer[i] == "FizzBuzz"if- iis divisible by- 3and- 5.
- answer[i] == "Fizz"if- iis divisible by- 3.
- answer[i] == "Buzz"if- iis divisible by- 5.
- answer[i] == i(as a string) if none of the above conditions are true.
Example 1:
Input: n = 3
Output: ["1","2","Fizz"]
Example 2:
Input: n = 5
Output: ["1","2","Fizz","4","Buzz"]
Example 3:
Input: n = 15
Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
Constraints:
- 1 <= n <= 104
Solution
  最后更新: October 11, 2023