FizzBuzz Solution (Java)


  • 2
    Y

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


Log in to reply
 

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