2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

412. FizzBuzz

Posted at

#Submission

submission.py
class Solution:
    def fizzBuzz(self, n: int) -> List[str]:
        ans = []
        for nums in range(1, n + 1):
            if nums % 15 == 0:
                ans.append("FizzBuzz")
            elif nums % 5 == 0:
                ans.append("Buzz")
            elif nums % 3 == 0:
                ans.append("Fizz")
            else:
                ans.append(str(nums))
        return ans
2
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?