mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
39 lines
1.2 KiB
HTML
39 lines
1.2 KiB
HTML
<p>Given an integer array <code>nums</code>, return <em>the number of <strong>reverse pairs</strong> in the array</em>.</p>
|
|
|
|
<p>A <strong>reverse pair</strong> is a pair <code>(i, j)</code> where:</p>
|
|
|
|
<ul>
|
|
<li><code>0 <= i < j < nums.length</code> and</li>
|
|
<li><code>nums[i] > 2 * nums[j]</code>.</li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [1,3,2,3,1]
|
|
<strong>Output:</strong> 2
|
|
<strong>Explanation:</strong> The reverse pairs are:
|
|
(1, 4) --> nums[1] = 3, nums[4] = 1, 3 > 2 * 1
|
|
(3, 4) --> nums[3] = 3, nums[4] = 1, 3 > 2 * 1
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> nums = [2,4,3,5,1]
|
|
<strong>Output:</strong> 3
|
|
<strong>Explanation:</strong> The reverse pairs are:
|
|
(1, 4) --> nums[1] = 4, nums[4] = 1, 4 > 2 * 1
|
|
(2, 4) --> nums[2] = 3, nums[4] = 1, 3 > 2 * 1
|
|
(3, 4) --> nums[3] = 5, nums[4] = 1, 5 > 2 * 1
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 5 * 10<sup>4</sup></code></li>
|
|
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
|
|
</ul>
|