Skip to content

Latest commit

 

History

History
 
 

fizzBuzz

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

fizz-buzz

LeetCode地址

程序

class Solution {
    public List<String> fizzBuzz(int n) {
        List<String> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            StringBuffer sb = new StringBuffer();
            if (i % 3 == 0) sb.append("Fizz");
            if (i % 5 == 0) sb.append("Buzz");
            if (sb.length() == 0) sb.append(String.valueOf(i));
            list.add(sb.toString());
        }
        return list;
    }
}