Java 4 lines solution, any criticism appreciated


  • 0
    U

    public List<String> fizzBuzz(int n) {
    List<String> list = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
    list.add(i%3==0?(i%5==0?"FizzBuzz":"Fizz"):(i%5==0?"Buzz":new Integer(i).toString()));
    }
    return list;
    }


Log in to reply
 

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