My Java Accepted solution


  • 1
    A

    My java Accepted solution to this problem:-

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

  • 0
    X

    the same to you


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.