Java ternary operator 4ms Solution


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

    }


Log in to reply
 

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