leetcode 412. Fizz Buzz
vector<string> fizzBuzz(int n) { vector<string> ret; for (int i = 1; i <= n; i++) { bool three = i % 3 == 0; bool five = i % 5 == 0; if (three && five) ret.push_back("FizzBuzz"); else if (three) ret.push_back("Fizz"); else if (five) ret.push_back("Buzz"); else ret.push_back(to_string(i)); } return move(ret); }
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】