Python实现【生日礼物】

360影视 动漫周边 2025-04-21 22:44 2

摘要:def count_purchase_plans(cake_prices, gift_prices, x):cake_prices.sortgift_prices.sortcount = 0left, right = 0, len(gift_prices) -

def count_purchase_plans(cake_prices, gift_prices, x):cake_prices.sortgift_prices.sortcount = 0left, right = 0, len(gift_prices) - 1# 使用双指针法统计满足条件的组合数目for cake in cake_prices:while right >= 0 and cake + gift_prices[right] > x:right -= 1if right 统计有效组合:在双指针遍历过程中,累加满足条件的组合数目。

来源:小雨课堂

相关推荐