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)/区间和的个数 [count-of-range-sum].html
2022-03-29 12:43:11 +08:00

31 lines
1.2 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>nums</code> 以及两个整数 <code>lower</code><code>upper</code> 。求数组中,值位于范围 <code>[lower, upper]</code> (包含 <code>lower</code> 和 <code>upper</code>)之内的 <strong>区间和的个数</strong></p>
<p><strong>区间和</strong> <code>S(i, j)</code> 表示在 <code>nums</code> 中,位置从 <code>i</code> 到 <code>j</code> 的元素之和,包含 <code>i</code> 和 <code>j</code> (<code>i</code><code>j</code>)。</p>
<p> </p>
<strong>示例 1</strong>
<pre>
<strong>输入:</strong>nums = [-2,5,-1], lower = -2, upper = 2
<strong>输出:</strong>3
<strong>解释:</strong>存在三个区间:[0,0]、[2,2] 和 [0,2] ,对应的区间和分别是:-2 、-1 、2 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [0], lower = 0, upper = 0
<strong>输出:</strong>1
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
<li><code>-10<sup>5</sup> <= lower <= upper <= 10<sup>5</sup></code></li>
<li>题目数据保证答案是一个 <strong>32 位</strong> 的整数</li>
</ul>