#412
Fizz Buzz
newbie · 235 · lc easy +18 · verified · 75.3% accepted · 3,347 likes · top 86%
Description
Given integer n, construct and return a 1-indexed string array of length n. For each index i, the corresponding entry follows these rules:
- "FizzBuzz" when i is divisible by both 3 and 5.
- "Fizz" when i is divisible by 3 only.
- "Buzz" when i is divisible by 5 only.
- The decimal string of i otherwise.
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"]
Code
1
2
3