lintcode 9. Fizz Buzz问题

难度:容易

1. Description

9. Fizz Buzz问题

2. Solution

  • python
    只让用一个if,但是可以用for呀
class Solution:
    """
    @param n: An integer
    @return: A list of strings.
    """
    def fizzBuzz(self, n):
        # write your code here
        res = [str(i) for i in range(1,n+1)]
        
        for i in range(2,n,3):
            res[i] = 'fizz'
        for i in range(4,n,5):
            if (i+1)%3==0:
                res[i] = 'fizz buzz'
                continue
            res[i] = 'buzz'
        return res

3. Reference

  1. https://www.lintcode.com/problem/fizz-buzz/description

你可能感兴趣的:(lintcode 9. Fizz Buzz问题)