0
点赞
收藏
分享

微信扫一扫

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

墨春 2022-11-04 阅读 71
编程语言

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 条评论