JAVA | 3 Approaches | Easy ✅
---\n# Please Upvote \uD83D\uDE07\n---\n## 1. Simple if-else:\n\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n        List<String> ans = new Arr
---\n# Please Upvote \uD83D\uDE07\n---\n## 1. Simple if-else:\n```\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n        List<String> ans = new ArrayList<>();\n        for (int i = 1; i <= n; i++) {\n            if (i % 15 == 0) {\n                ans.add("FizzBuzz");\n            } else if (i % 3 == 0) {\n                ans.add("Fizz");\n            } else if (i % 5 == 0) {\n                ans.add("Buzz");\n            } else {\n                ans.add(String.valueOf(i));\n            }\n        }\n                         \n        return ans;                 \n    }\n}\n\n// TC: O(n), SC: O(n)\n```\n---\n## 2. No % :\n```\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n        List<String> res = new ArrayList<>();\n        int i = 1, fizz = 0, buzz = 0;\n        while (i <= n){\n            fizz++; buzz++;\n            if (fizz == 3 && buzz == 5) {\n                res.add("FizzBuzz");\n                fizz = buzz = 0;\n            } else if (fizz == 3) {\n                res.add("Fizz");\n                fizz = 0;\n            } else if (buzz == 5) {\n                res.add("Buzz");\n                buzz = 0;\n            } else {\n                res.add(String.valueOf(i));\n            }\n            i++;\n        }\n\n        return res;\n    }\n}\n\n// TC: O(n), SC: O(n)\n```\n---\n## 3. Ternery Operator:\n``` \nclass Solution {\n    public List fizzBuzz(int n) {\n        List ans = new ArrayList<>();\n        for(int i = 1; i <= n; i++){\n            ans.add(\n                i % 15 == 0 ? "FizzBuzz" :\n                i % 5 == 0  ? "Buzz" :\n                i % 3 == 0  ? "Fizz" :\n                String.valueOf(i)\n            );\n        }\n\n        return ans;\n    }\n}\n\n// TC: O(n), SC: O(n)\n```
['Math', 'Java']