1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/停在原地的方案数 [number-of-ways-to-stay-in-the-same-place-after-some-steps].html
2022-03-29 12:43:11 +08:00

48 lines
1.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>有一个长度为 <code>arrLen</code> 的数组,开始有一个指针在索引 <code>0</code> 处。</p>
<p>每一步操作中,你可以将指针向左或向右移动 1 步,或者停在原地(指针不能被移动到数组范围外)。</p>
<p>给你两个整数 <code>steps</code> 和 <code>arrLen</code> ,请你计算并返回:在恰好执行 <code>steps</code> 次操作以后,指针仍然指向索引 <code>0</code> 处的方案数。</p>
<p>由于答案可能会很大,请返回方案数 <strong></strong> <code>10^9 + 7</code> 后的结果。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>steps = 3, arrLen = 2
<strong>输出:</strong>4
<strong>解释:</strong>3 步后,总共有 4 种不同的方法可以停在索引 0 处。
向右,向左,不动
不动,向右,向左
向右,不动,向左
不动,不动,不动
</pre>
<p><strong>示例  2</strong></p>
<pre>
<strong>输入:</strong>steps = 2, arrLen = 4
<strong>输出:</strong>2
<strong>解释:</strong>2 步后,总共有 2 种不同的方法可以停在索引 0 处。
向右,向左
不动,不动
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>steps = 4, arrLen = 2
<strong>输出:</strong>8
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= steps <= 500</code></li>
<li><code>1 <= arrLen <= 10<sup>6</sup></code></li>
</ul>