下面是AC代码,C++风格:
class Solution {
public:
vector<string> fizzBuzz(int N) {
vector<string> Answer;
for(int i = ;i <= N;i++) {
if(i % == ) {
Answer.push_back("fizz buzz");
} else if(i % == ) {
Answer.push_back("fizz");
} else if(i % == ) {
Answer.push_back("buzz");
} else{
Answer.push_back(to_string(i));
}
}
return Answer;
}
};
此处很奇怪,为何将成员函数名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