Simple Java || C++ Code ☠️
java []\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n        ArrayList<String> list = new ArrayList<>();\n        for(int i=1;i<=n;i++){\n     
```java []\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n        ArrayList<String> list = new ArrayList<>();\n        for(int i=1;i<=n;i++){\n            if(i%3==0 && i%5==0){\n                list.add("FizzBuzz");\n            }\n            else if(i%3==0){\n                list.add("Fizz");\n            }\n            else if(i%5==0){\n                list.add("Buzz");\n            }\n            else{\n                list.add(Integer.toString(i));\n            }\n        }\n        return list;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    vector<string> fizzBuzz(int n) {\n        vector<string> list;\n        for(int i=1;i<=n;i++){\n            if(i%3==0 && i%5==0){\n                list.push_back("FizzBuzz");\n            }\n            else if(i%3==0){\n                list.push_back("Fizz");\n            }\n            else if(i%5==0){\n                list.push_back("Buzz");\n            }\n            else{\n                list.push_back(to_string(i));\n            }\n        }\n        return list;\n    }\n};\n```\n\n\n\n### Detailed Breakdown\n1. **Initialization**:\n    - An `ArrayList` named `list` is initialized to store the results.\n    ```java\n    ArrayList<String> list = new ArrayList<>();\n    ```\n\n2. **Loop Through Numbers**:\n    - A `for` loop is used to iterate from `1` to `n` (inclusive).\n    ```java\n    for(int i = 1; i <= n; i++) {\n    ```\n\n3. **Condition Checking**:\n    - Inside the loop, multiple conditions are checked for each number `i`:\n      - **Divisible by 3 and 5**:\n        - If `i` is divisible by both 3 and 5, "FizzBuzz" is added to the list.\n        ```java\n        if(i % 3 == 0 && i % 5 == 0) {\n            list.add("FizzBuzz");\n        }\n        ```\n      - **Divisible by 3**:\n        - If `i` is divisible by 3, "Fizz" is added to the list.\n        ```java\n        else if(i % 3 == 0) {\n            list.add("Fizz");\n        }\n        ```\n      - **Divisible by 5**:\n        - If `i` is divisible by 5, "Buzz" is added to the list.\n        ```java\n        else if(i % 5 == 0) {\n            list.add("Buzz");\n        }\n        ```\n      - **None of the Above**:\n        - If none of the above conditions are true, the string representation of `i` is added to the list.\n        ```java\n        else {\n            list.add(Integer.toString(i));\n        }\n        ```\n\n4. **Return the List**:\n    - After the loop ends, the list `list` containing the results is returned.\n    ```java\n    return list;\n    ```\n\n### Time and Space Complexity\n- **Time Complexity**: O(n), where `n` is the input integer. This is because the loop iterates from 1 to `n` and performs constant-time operations within each iteration.\n- **Space Complexity**: O(n), as the list stores `n` elements (one for each number from 1 to `n`).\n\n\n\n\n
['Math', 'String', 'Simulation', 'C++', 'Java']