scala version


  • 0
    M
      def fizzBuzz(n: Int): List[String] = {
        var list = List.empty[String]
        var arr = Array.empty[Int]
        (1 to n).foreach {
          case x if x % 3 == 0 && x % 5 != 0 => list :+= "Fizz"
          case y if y % 3 != 0 && y % 5 == 0 => list :+= "Buzz"
          case z if z % 3 == 0 && z % 5 == 0 => list :+= "FizzBuzz"
          case none => list :+= none.toString
        }
        list
      }
    

Log in to reply
 

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