100% runtime in java and C++ implementation
Java Implementation \n\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n\n        // ans list\n        List<String> ans = new ArrayList<String>();\
Java Implementation \n```\nclass Solution {\n    public List<String> fizzBuzz(int n) {\n\n        // ans list\n        List<String> ans = new ArrayList<String>();\n\n        for (int num = 1; num <= n; num++) {\n\n            boolean divisibleBy3 = (num % 3 == 0);\n            boolean divisibleBy5 = (num % 5 == 0);\n\n            if (divisibleBy3 && divisibleBy5) {\n                // Divides by both 3 and 5, add FizzBuzz\n                ans.add("FizzBuzz");\n            } else if (divisibleBy3) {\n                // Divides by 3, add Fizz\n                ans.add("Fizz");\n            } else if (divisibleBy5) {\n                // Divides by 5, add Buzz\n                ans.add("Buzz");\n            } else {\n                // Not divisible by 3 or 5, add the number\n                ans.add(Integer.toString(num));\n            }\n        }\n\n        return ans;\n    }\n}\n```\n\nC++ Implementation \n\n```\nclass Solution {\npublic:\n    vector<string> fizzBuzz(int n) {\n        vector<string> fizzBuzz;\n        string temp;\n            for(int i=1; i <=n; i++){\n                string temp = "";\n                if( i % 3 == 0 || i % 5 == 0){\n                    if( i % 3 == 0 )\n                        temp = "Fizz";\n                    if ( i % 5 == 0)\n                        temp = temp + "Buzz";\n                }\n                else\n                    temp = to_string(i);\n                fizzBuzz.push_back(temp);\n            }\n        return fizzBuzz;\n    }\n};\n``\n
[]