Skip to content

Commit dcb4871

Browse files
committed
Runtime: 32 ms (Top 100.0%) | Memory: 3.70 MB (Top 100.0%)
1 parent c9dbdf1 commit dcb4871

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Runtime: 32 ms (Top 100.0%) | Memory: 3.70 MB (Top 100.0%)
2+
3+
impl Solution {
4+
pub fn count_fair_pairs(mut nums: Vec<i32>, lower: i32, upper: i32) -> i64 {
5+
nums.sort_unstable();
6+
let mut ans = 0i64;
7+
for (idx, num) in nums.iter().copied().enumerate() {
8+
let l_bound = nums[idx+1..].partition_point(|&n| n+num < lower);
9+
let u_bound = nums[idx+1..].partition_point(|&n| n+num <= upper);
10+
ans += (u_bound - l_bound) as i64;
11+
}
12+
ans
13+
}
14+
}

0 commit comments

Comments
 (0)