Java 5ms solution


  • 0
    X

    """
    public List<String> fizzBuzz(int n) {
    List<String> list = new ArrayList<String>();
    for(int i = 1; i<=n; i++){
    if(i%3 == 0 && i%5 != 0){
    list.add("Fizz");
    continue;
    }
    if(i%5 == 0 && i%3 != 0){
    list.add("Buzz");
    continue;
    }
    if(i%(3*5) == 0){
    list.add("FizzBuzz");
    continue;
    }
    list.add(""+i);
    }
    return list;
    }
    """


Log in to reply
 

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