下面是AC代码,C++风格:
1 class Solution {
2 public:
3 vector<string> fizzBuzz(int N) {
4 vector<string> Answer;
5 for(int i = 1;i <= N;i++) {
6 if(i % 15 == 0) {
7 Answer.push_back("fizz buzz");
8 } else if(i % 3 == 0) {
9 Answer.push_back("fizz");
10 } else if(i % 5 == 0) {
11 Answer.push_back("buzz");
12 } else{
13 Answer.push_back(to_string(i));
14 }
15 }
16 return Answer;
17 }
18 };
此处很奇怪,为何将成员函数名fizzBuzz的首字母改成大写,编译返回不通过?
编译警告
Main.cpp: In function ‘int main()’:
Main.cpp:26:39: error: ‘class Solution’ has no member named ‘fizzBuzz’
vector results = solution.fizzBuzz(n);
^
EXITCODE=1