# 412.Fizz Buzz

**412.Fizz Buzz**

难度:Easy

> 写一个程序，输出从 1 到 n 数字的字符串表示。

1. 如果 n 是3的倍数，输出“Fizz”；
2. 如果 n 是5的倍数，输出“Buzz”；

3.如果 n 同时是3和5的倍数，输出 “FizzBuzz”。

```
示例：

n = 15,

返回:
[
    "1",
    "2",
    "Fizz",
    "4",
    "Buzz",
    "Fizz",
    "7",
    "8",
    "Fizz",
    "Buzz",
    "11",
    "Fizz",
    "13",
    "14",
    "FizzBuzz"
]
```

简单题，

```
class Solution {
public:
    vector<string> fizzBuzz(int n) {
        int s=res.size();
        if(s>=n)
            return vector<string>(res.begin(),res.begin()+n);
        
        for(int i=s+1;i<=n;i++)
            if(i%15==0) res.push_back("FizzBuzz");
            else if(i%5 ==0) res.push_back("Buzz");
            else if(i%3 ==0) res.push_back("Fizz");
            else res.push_back(to_string(i));
        return res;
        
    }
private:
    vector<string> res={"1","2","Fizz","4","Buzz"};
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/412.fizz_buzz.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
