✅ 🔥 0 ms Runtime Beats 100% User confirm 🔥|| Step By Steps Solution ✅ ||  Biginner Friendly  ✅ |
\u2705  IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition:\nThe problem is a classic "FizzBuzz" exercise where we iterate through nu
\u2705  IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition:\nThe problem is a classic "FizzBuzz" exercise where we iterate through numbers and replace specific multiples with corresponding strings. The key is to check conditions in order of priority:\n1. Numbers divisible by both 3 and 5.\n2. Numbers divisible by 3.\n3. Numbers divisible by 5.\n4. Otherwise, represent the number as a string.\n\n### Approach:\n1. Create an empty result list.\n2. Iterate from 1 to \\( n \\):\n   - If \\( i \\) is divisible by both 3 and 5, append "FizzBuzz".\n   - Else if \\( i \\) is divisible by 3, append "Fizz".\n   - Else if \\( i \\) is divisible by 5, append "Buzz".\n   - Otherwise, append the string representation of \\( i \\).\n3. Return the list.\n\n### Complexity:\n- **Time Complexity**: \\( O(n) \\), as we iterate from 1 to \\( n \\).\n- **Space Complexity**: \\( O(n) \\), as we store the result in a list.\n\n---\n\n### C++ Code:\n```cpp\n#include<vector>\n#include<string>\nusing namespace std;\nclass Solution{\npublic:\nvector<string>fizzBuzz(int n){\nvector<string>result;\nfor(int i=1;i<=n;i++){\nif(i%3==0&&i%5==0){\nresult.push_back("FizzBuzz");\n}else if(i%3==0){\nresult.push_back("Fizz");\n}else if(i%5==0){\nresult.push_back("Buzz");\n}else{\nresult.push_back(to_string(i));\n}\n}\nreturn result;\n}\n};\n\n```\n\n---\n\n### Java Code:\n```java\nimport java.util.*;\nclass Solution{\npublic List<String>fizzBuzz(int n){\nList<String>result=new ArrayList<>();\nfor(int i=1;i<=n;i++){\nif(i%3==0&&i%5==0){\nresult.add("FizzBuzz");\n}else if(i%3==0){\nresult.add("Fizz");\n}else if(i%5==0){\nresult.add("Buzz");\n}else{\nresult.add(Integer.toString(i));\n}\n}\nreturn result;\n}\n}\n\n```\n\n---\n\n### Python 3 Code:\n```python\nclass Solution:\ndef fizzBuzz(self,n:int)->List[str]:\nresult=[]\nfor i in range(1,n+1):\nif i%3==0 and i%5==0:\nresult.append("FizzBuzz")\nelif i%3==0:\nresult.append("Fizz")\nelif i%5==0:\nresult.append("Buzz")\nelse:\nresult.append(str(i))\nreturn result\n\n```\n![image.png](https://assets.leetcode.com/users/images/edd64ea4-37ab-46bb-b26a-2ff10b5252ee_1731811734.1862714.png)\n
['Math', 'String', 'C++', 'Java', 'Python3']