# Leetcode Algorithm

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”.

**Example:**

n = 15,Return:

[

"1",

"2",

"Fizz",

"4",

"Buzz",

"Fizz",

"7",

"8",

"Fizz",

"Buzz",

"11",

"Fizz",

"13",

"14",

"FizzBuzz"

]

Logic:

- Create an empty list as “ans”
- Loop from 1 to n, and check each values in the loop. Check them with 15 firstly, and then 5, and then 3. Use modulus to check each values
- Notice that the output list is a list of strings. So, we have to convert the values in the step 2 to strings, before appending them in a list.

Solution:

`class Solution:`

def fizzBuzz(self, n: int) -> List[str]:

ans = []

for x in range(1, n+1):

n = str(x) # convert int to string

if x % 15 == 0: # multiplier of 15

n = "FizzBuzz"

elif x % 5 == 0:

n = "Buzz"

elif x % 3 == 0:

n = "Fizz"

ans.append(n)

return ans