-
Notifications
You must be signed in to change notification settings - Fork 0
/
412.hpp
59 lines (52 loc) · 980 Bytes
/
412.hpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef LEETCODE_412_HPP
#define LEETCODE_412_HPP
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
/*
n = 15,
Return:
[
"1",
"2",
"Fizz",
"4",
"Buzz",
"Fizz",
"7",
"8",
"Fizz",
"Buzz",
"11",
"Fizz",
"13",
"14",
"FizzBuzz"
]
*/
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> result(static_cast<unsigned long>(n));
for (int i = 0; i < n; ++i) {
if ((i + 1) % 15 == 0)
result[i] = "FizzBuzz";
else if ((i + 1) % 5 == 0)
result[i] = "Buzz";
else if ((i + 1) % 3 == 0)
result[i] = "Fizz";
else
result[i] = to_string(i + 1);
}
return result;
}
};
#endif //LEETCODE_412_HPP