mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
39 lines
1.2 KiB
HTML
39 lines
1.2 KiB
HTML
<p>给你一个整数 <code>n</code> ,找出从 <code>1</code> 到 <code>n</code> 各个整数的 Fizz Buzz 表示,并用字符串数组 <code>answer</code>(<strong>下标从 1 开始</strong>)返回结果,其中:</p>
|
||
|
||
<ul>
|
||
<li><code>answer[i] == "FizzBuzz"</code> 如果 <code>i</code> 同时是 <code>3</code> 和 <code>5</code> 的倍数。</li>
|
||
<li><code>answer[i] == "Fizz"</code> 如果 <code>i</code> 是 <code>3</code> 的倍数。</li>
|
||
<li><code>answer[i] == "Buzz"</code> 如果 <code>i</code> 是 <code>5</code> 的倍数。</li>
|
||
<li><code>answer[i] == i</code> (以字符串形式)如果上述条件全不满足。</li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 3
|
||
<strong>输出:</strong>["1","2","Fizz"]
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 5
|
||
<strong>输出:</strong>["1","2","Fizz","4","Buzz"]
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>n = 15
|
||
<strong>输出:</strong>["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= n <= 10<sup>4</sup></code></li>
|
||
</ul>
|