JAVA EASY SOLUTION BEATS 99.7%
Intuition\n Describe your first thoughts on how to solve this problem. \nThe given code is iterating over each integer from 1 to n and checking whether the inte
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe given code is iterating over each integer from 1 to n and checking whether the integer is divisible by 3 or 5 or both. Depending on the divisibility, the corresponding string value is added to the list of strings. If the integer is not divisible by 3 or 5, then it is added to the list as a string. Finally, the list of strings is returned as the output. This approach is straightforward and efficient in terms of both time and space complexity.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach used in the given code is to iterate over each integer from 1 to n and check whether the integer is divisible by 3 or 5 or both. Depending on the divisibility, the corresponding string value is added to the list of strings. If the integer is not divisible by 3 or 5, then it is added to the list as a string.\n\n# Complexity\n- Time complexity: \nThe time complexity of the given code is O(n) since it iterates over each integer from 1 to n.\n\n\n\n- Space complexity:\nThe space complexity of the given code is also O(n) since it uses an ArrayList to store the FizzBuzz values for each integer from 1 to n.\n\n# Code\n```\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n        ArrayList<String> a = new ArrayList<String>();\n        for(int i=1;i<=n;i++){\n            if(i%3==0&&i%5!=0)\n            a.add("Fizz");\n            else if(i%5==0&&i%3!=0)\n            a.add("Buzz");\n            else if(i%3==0&&i%5==0)\n            a.add("FizzBuzz");\n            else a.add(Integer.toString(i));\n        }\n        return a;\n    }\n}\n```
['Math', 'String', 'Simulation', 'Java']