2563. Count the Number of Fair Pairs Medium
1/**
2 * [2563] Count the Number of Fair Pairs
3 *
4 * Given a 0-indexed integer array nums of size n and two integers lower and upper, return the number of fair pairs.
5 * A pair (i, j) is fair if:
6 *
7 * 0 <= i < j < n, and
8 * lower <= nums[i] + nums[j] <= upper
9 *
10 *
11 * <strong class="example">Example 1:
12 *
13 * Input: nums = [0,1,7,4,4,5], lower = 3, upper = 6
14 * Output: 6
15 * Explanation: There are 6 fair pairs: (0,3), (0,4), (0,5), (1,3), (1,4), and (1,5).
16 *
17 * <strong class="example">Example 2:
18 *
19 * Input: nums = [1,7,9,2,5], lower = 11, upper = 11
20 * Output: 1
21 * Explanation: There is a single fair pair: (2,3).
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= nums.length <= 10^5
27 * nums.length == n
28 * <font face="monospace">-10^9</font> <= nums[i] <= 10^9
29 * <font face="monospace">-10^9 <= lower <= upper <= 10^9</font>
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/count-the-number-of-fair-pairs/
35// discuss: https://leetcode.com/problems/count-the-number-of-fair-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn count_fair_pairs(nums: Vec<i32>, lower: i32, upper: i32) -> i64 {
41
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2563() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.