LeetCode 412. Fizz Buzz
IPFS
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; } }
Like my work? Don't forget to support and clap, let me know that you are with me on the road of creation. Keep this enthusiasm together!