Ruby Solution


  • 0
    I
    # @param {Integer} n
    # @return {String[]}
    def fizz_buzz(n)
        1.upto(n).map do |i|
           if i % 3 == 0
               if i % 5 == 0
                   "FizzBuzz"
               else
                "Fizz"
               end
           elsif i % 5 == 0
               "Buzz"
           else
               i.to_s
           end
        end
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.