Simple solution by Java 8 Stream API:


  • 0
    X
    return IntStream.range(1, n + 1)
                    .mapToObj(i -> i % 15 == 0 ? "FizzBuzz" : (i % 3 == 0 ? "Fizz" : (i % 5 == 0 ? "Buzz" : String.valueOf(i))))
                    .collect(Collectors.toList());
    

Log in to reply
 

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