-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathFizzBuzz.cpp
More file actions
32 lines (31 loc) · 710 Bytes
/
Copy pathFizzBuzz.cpp
File metadata and controls
32 lines (31 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<string.h>
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> s;
for(int i=1; i<=n; i++)
{
if(i%5 == 0 && i%3 == 0)
{
s.push_back("FizzBuzz");
continue;
}
if(i%3==0)
{
s.push_back("Fizz");
continue;
}
if(i%5==0)
{
s.push_back("Buzz");
continue;
}
else{
s.push_back(to_string(i));
}
}
return s;
}
};
// Time Complexity - O(n)
// Space Complexity - O(n) -- using a vector