Java short if solution 4ms


  • 0
    R

    With short if

    public class Solution {
        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":i%3==0?"Fizz":i%5==0?"Buzz":Integer.toString(i));
            }
            return list;
        }
    }
    

Log in to reply
 

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