GuilinDev

Lc0412

05 August 2008

412 Fizz Buzz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
    public List<String> fizzBuzz(int n) {
        
        List<String> data = new ArrayList<>();
        
        for(int i = 1 ; i <= n ; i++){
           
            if(i % 15 == 0){
                data.add("FizzBuzz");
            }else if(i % 3 == 0){
                data.add("Fizz");
            }else if(i % 5 == 0){
                data.add("Buzz");
            }else{
                data.add(String.valueOf(i));
            }
            
        }
        
        return data;
        
    }
}