Class Solution
java.lang.Object
g2501_2600.s2563_count_the_number_of_fair_pairs.Solution
2563 - Count the Number of Fair Pairs.<p>Medium</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code> of size <code>n</code> and two integers <code>lower</code> and <code>upper</code>, return <em>the number of fair pairs</em>.</p>
<p>A pair <code>(i, j)</code> is <strong>fair</strong> if:</p>
<ul>
<li><code>0 <= i < j < n</code>, and</li>
<li><code>lower <= nums[i] + nums[j] <= upper</code></li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [0,1,7,4,4,5], lower = 3, upper = 6</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,7,9,2,5], lower = 11, upper = 11</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> There is a single fair pair: (2,3).</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>nums.length == n</code></li>
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
<li><code>-10<sup>9</sup> <= lower <= upper <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countFairPairs
public long countFairPairs(int[] nums, int lower, int upper)
-