Java easy!


  • 0
    G

    My code,easy to understand.

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

Log in to reply
 

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