mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
47 lines
1.6 KiB
HTML
47 lines
1.6 KiB
HTML
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>target</code> 。</p>
|
||
|
||
<p>请你统计并返回 <code>nums</code> 中能满足其最小元素与最大元素的 <strong>和</strong> 小于或等于 <code>target</code> 的 <strong>非空</strong> 子序列的数目。</p>
|
||
|
||
<p>由于答案可能很大,请将结果对<meta charset="UTF-8" /> <code>10<sup>9</sup> + 7</code> 取余后返回。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [3,5,6,7], target = 9
|
||
<strong>输出:</strong>4
|
||
<strong>解释:</strong>有 4 个子序列满足该条件。
|
||
[3] -> 最小元素 + 最大元素 <= target (3 + 3 <= 9)
|
||
[3,5] -> (3 + 5 <= 9)
|
||
[3,5,6] -> (3 + 6 <= 9)
|
||
[3,6] -> (3 + 6 <= 9)
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [3,3,6,8], target = 10
|
||
<strong>输出:</strong>6
|
||
<strong>解释:</strong>有 6 个子序列满足该条件。(nums 中可以有重复数字)
|
||
[3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [2,3,3,4,6,7], target = 12
|
||
<strong>输出:</strong>61
|
||
<strong>解释:</strong>共有 63 个非空子序列,其中 2 个不满足条件([6,7], [7])
|
||
有效序列总数为(63 - 2 = 61)
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
||
<li><code>1 <= target <= 10<sup>6</sup></code></li>
|
||
</ul>
|