fix(posts): fetch daily from files
This commit is contained in:
parent
3d2ee97afe
commit
2bcc3f4675
9 changed files with 691 additions and 0 deletions
16
public/code/algorithms/leetcode-daily/cfps-twoptr.py
Normal file
16
public/code/algorithms/leetcode-daily/cfps-twoptr.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
def countFairPairs(self, nums, lower, upper):
|
||||
nums.sort()
|
||||
ans = 0
|
||||
|
||||
def pairs_leq(x: int) -> int:
|
||||
pairs = 0
|
||||
l, r = 0, len(nums) - 1
|
||||
while l < r:
|
||||
if nums[l] + nums[r] <= x:
|
||||
pairs += r - l
|
||||
l += 1
|
||||
else:
|
||||
r -= 1
|
||||
return pairs
|
||||
|
||||
return pairs_leq(upper) - pairs_leq(lower - 1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue