Skip to content

Commit c219f5f

Browse files
committed
2563
1 parent 3839747 commit c219f5f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Nov-13-24.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def countFairPairs(self, nums: List[int], lower: int, upper: int) -> int:
3+
def countPairsSum(val):
4+
l,r = 0,len(nums)-1
5+
res = 0
6+
while l<r:
7+
while l<r and nums[l]+nums[r]>val:
8+
r -= 1
9+
res += r-l
10+
l += 1
11+
return res
12+
ans = 0
13+
nums.sort()
14+
return countPairsSum(upper) - countPairsSum(lower-1)

0 commit comments

Comments
 (0)