1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/满足条件的子序列数目 [number-of-subsequences-that-satisfy-the-given-sum-condition].html
2022-03-29 12:43:11 +08:00

47 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>nums</code> 和一个整数 <code>target</code></p>
<p>请你统计并返回 <code>nums</code> 中能满足其最小元素与最大元素的 <strong></strong> 小于或等于 <code>target</code><strong>非空</strong> 子序列的数目。</p>
<p>由于答案可能很大,请将结果对<meta charset="UTF-8" />&nbsp;<code>10<sup>9</sup>&nbsp;+ 7</code>&nbsp;取余后返回。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [3,5,6,7], target = 9
<strong>输出:</strong>4
<strong>解释:</strong>有 4 个子序列满足该条件。
[3] -&gt; 最小元素 + 最大元素 &lt;= target (3 + 3 &lt;= 9)
[3,5] -&gt; (3 + 5 &lt;= 9)
[3,5,6] -&gt; (3 + 6 &lt;= 9)
[3,6] -&gt; (3 + 6 &lt;= 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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= target &lt;= 10<sup>6</sup></code></li>
</ul>