LeetCode 412. Fizz Buzz
class Solution { public List<String> fizzBuzz(int n) { ArrayList<String> al = new ArrayList<>(n); al.clear(); for(int i=1; i<=n; i++){ boolean divisible3 = i%3==0; boolean divisible5 = i%5==0; String str=""; if(divisible3) { str+="Fizz"; } if(divisible5) { str+="Buzz"; } if(str.isEmpty()) { str += String.valueOf(i); } al.add(str); } return al; } }