LeetCode之412. Fizz Buzz

--------------------------------------------

 

虽然是从最简单的开始刷起,但木有想到LeetCode上也有这么水的题目啊。。。

 

AC代码:

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

 

题目来源: https://leetcode.com/problems/fizz-buzz/

相关文章:

  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
猜你喜欢
  • 2021-07-31
  • 2021-10-19
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-01-19
  • 2022-01-01
相关资源
相似解决方案