FizzBuzz Solution (Java)


  • 0

    public List<String> fizzBuzz(int n) {
    String [] arr = new String[n];
    for(int i = 1; i <= arr.length; i++){
    if(i % 15 == 0){
    arr[i - 1] = "Fizz";
    } else if(i % 5 == 0){
    arr[i - 1] = "Buzz";
    } else if(i % 3 == 0){
    arr[i - 1] = "FizzBuzz";
    } else {
    arr[i - 1] = i+"";
    }
    }
    return Arrays.asList(arr);
    }


Log in to reply
 

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