---
# System prepended metadata

title: 'FizzBuzz <img src="https://img.shields.io/badge/-easy-brightgreen">'
tags: [data_structure_python]

---

---
tags: data_structure_python
---

# FizzBuzz <img src="https://img.shields.io/badge/-easy-brightgreen">

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"
]
```

### Solution

```python=
class Solution:
    def fizzBuzz(self, n: int) -> List[str]:
        res, i = [], 1
        while i < n+1:
            s = ""
            if i%3==0:
                s += "Fizz"
            if i%5==0:
                s += "Buzz"
            if s == "":
                s += str(i)
            res.append(s)
            i += 1
        
        return res
```