mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
53 lines
1.9 KiB
HTML
53 lines
1.9 KiB
HTML
<p>给你一个长度为 <code>n</code> 的 <strong>正</strong> 整数数组 <code>nums</code> 。</p>
|
||
|
||
<p>如果两个 <strong>非负</strong> 整数数组 <code>(arr1, arr2)</code> 满足以下条件,我们称它们是 <strong>单调</strong> 数组对:</p>
|
||
|
||
<ul>
|
||
<li>两个数组的长度都是 <code>n</code> 。</li>
|
||
<li><code>arr1</code> 是单调<strong> 非递减</strong> 的,换句话说 <code>arr1[0] <= arr1[1] <= ... <= arr1[n - 1]</code> 。</li>
|
||
<li><code>arr2</code> 是单调 <strong>非递增</strong> 的,换句话说 <code>arr2[0] >= arr2[1] >= ... >= arr2[n - 1]</code> 。</li>
|
||
<li>对于所有的 <code>0 <= i <= n - 1</code> 都有 <code>arr1[i] + arr2[i] == nums[i]</code> 。</li>
|
||
</ul>
|
||
|
||
<p>请你返回所有 <strong>单调</strong> 数组对的数目。</p>
|
||
|
||
<p>由于答案可能很大,请你将它对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后返回。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [2,3,2]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>4</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>单调数组对包括:</p>
|
||
|
||
<ol>
|
||
<li><code>([0, 1, 1], [2, 2, 1])</code></li>
|
||
<li><code>([0, 1, 2], [2, 2, 0])</code></li>
|
||
<li><code>([0, 2, 2], [2, 1, 0])</code></li>
|
||
<li><code>([1, 2, 2], [1, 1, 0])</code></li>
|
||
</ol>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [5,5,5,5]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>126</span></p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= n == nums.length <= 2000</code></li>
|
||
<li><code>1 <= nums[i] <= 50</code></li>
|
||
</ul>
|