Python笔试题:小力将 N 个零件的报价存于数组 nums。小力预算为 target

墨春

关注

阅读 71

2022-11-04

Python笔试题:小力将 N 个零件的报价存于数组 nums。小力预算为 target_其它

 

 

def test1(nums, target):
nums.sort() #先排序
left,right = 0,len(nums)-1
n = 0
while(left < right):
if(nums[left] + nums[right] > target):
right -= 1
else:
n += (right - left)
left += 1
return n%(10**9+7)

nums = [2,2,1,9]
target = 10
print(test1(nums,target))

 



相关推荐

精彩评论(0)

0 0 举报