2023-12-09 18:42:21 +08:00
|
|
|
|
<p>给定一个整型参数 <code>n</code>,请你编写并返回一个 <code>counter</code><strong> </strong>函数。这个 <code>counter</code><strong> </strong>函数最初返回 <code>n</code>,每次调用它时会返回前一个值加 1 的值 ( <code>n</code> , <code>n + 1</code> , <code>n + 2</code> ,等等)。</p>
|
2023-04-23 22:41:08 +08:00
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入:</strong>
|
2023-04-23 22:41:08 +08:00
|
|
|
|
n = 10
|
|
|
|
|
["call","call","call"]
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输出:</strong>[10,11,12]
|
|
|
|
|
<strong>解释:</strong>
|
|
|
|
|
counter() = 10 // 第一次调用 counter(),返回 n。
|
2023-04-23 22:41:08 +08:00
|
|
|
|
counter() = 11 // 返回上次调用的值加 1。
|
|
|
|
|
counter() = 12 // 返回上次调用的值加 1。
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 2:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入:</strong>
|
2023-04-23 22:41:08 +08:00
|
|
|
|
n = -2
|
|
|
|
|
["call","call","call","call","call"]
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输出:</strong>[-2,-1,0,1,2]
|
|
|
|
|
<strong>解释:</strong>counter() 最初返回 -2。然后在每个后续调用后增加 1。
|
2023-04-23 22:41:08 +08:00
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>-1000<sup> </sup><= n <= 1000</code></li>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<li><code>0 <= calls.length <= 1000</code></li>
|
|
|
|
|
<li><code>calls[i] === "call"</code></li>
|
2023-04-23 22:41:08 +08:00
|
|
|
|
</ul>
|