MCPcopy
hub / github.com/doocs/leetcode / fizzBuzz

Method fizzBuzz

solution/0400-0499/0412.Fizz Buzz/Solution.java:2–18  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

lengthMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected