当前位置:网站首页>【二分查找-简单】LCP 18. 早餐组合
【二分查找-简单】LCP 18. 早餐组合
2022-04-21 15:08:00 【菜菜2022】
题目
注意:答案需要以 1e9 + 7 (1000000007) 为底取模,如:计算初始结果为:1000000008,请返回 1
提示:
1 <= staple.length <= 10^5
1 <= drinks.length <= 10^5
1 <= staple[i],drinks[i] <= 10^5
1 <= x <= 2*10^5
【代码】
执行用时:1064 ms, 在所有 Python3 提交中击败了11.97% 的用户
内存消耗:28.6 MB, 在所有 Python3 提交中击败了96.95% 的用户
通过测试用例:65 / 65
class Solution:
def breakfastNumber(self, staple: List[int], drinks: List[int], x: int) -> int:
ans=0
staple.sort()
drinks.sort()
for item in staple:
#寻找drinks中从左到右 第一个大于>x-item的 数字下标
if x-item<=0:
continue
left,right=0,len(drinks)-1
while left<=right:
mid=left+(right-left)//2
if drinks[mid]<=(x-item):
left=mid+1
else:
right=mid-1
ans+=left
return ans%(10**9 + 7 )
版权声明
本文为[菜菜2022]所创,转载请带上原文链接,感谢
https://blog.csdn.net/kz_java/article/details/124272457
边栏推荐
- 开发者openshift4使用入门教程 - 16 - 使用init container挂载pinpoint APM监控
- Storage system and memory
- [today in history] April 21: microprocessor pioneer was born; Winamp release; Coppa comes into force
- &lt;译文&gt;设置Prometheus并将其与Grafana集成以进行监控
- Lightgbm topic 5: data consolidation of pyspark table data processing
- 干货 | 环境问题还是测试的老大难?两个步骤轻松搞定
- 数据库基础知识详解五:MySQL中的索引和其两种引擎、主从复制以及关系型/非关系型数据库
- 嵌入式开发:重新利用开发板进行测试的3个技巧
- 【JS】URLSearchParams 对象(以对象的形式上传参数到url)
- 武汉科技大学C语言上机实验题(第一第二第三部分)
猜你喜欢

Mysql数据库(2)

Mysql database (3)

京东云重磅发布云电脑,面向未来打造无界办公体验

Shang Silicon Valley smart campus - 6. Realization of administrator function

Service中是如何产生ANR的?

Mysql数据库(3)

pytorch图像分类篇:pytorch官方demo实现一个分类器(LeNet)

【天梯赛】L2-040 哲哲打游戏 (25 point(s))(模拟)

It's been 2 years since the career change test. Give some advice to girls who are still hesitating

如何选择合适的 Neo4j 版本(2022)
随机推荐
干货 | 移动端App自动化之App控件定位
让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
C# 11 对 ref 和 struct 的改进
android.database.sqlite.SQLiteException: Can't downgrade database from version 2 to 1
基于JSP的公益网站设计与实现
Amazon evaluates the autotrophic number. What should sellers do if they want to get a review?
归纳偏置/归纳偏差/inductive bias
Tutoriel de développement d'applications SAP ui5 70 - Comment utiliser un contrôle de bouton pour déclencher un saut de routage de page
蟲子 插入 希爾
DABDetr论文解读+核心源码解读
Deploy the big pit of edgemesh on kubesphere
智慧公安二维码定位报警系统开发 移动警务app
怎么去约束代码的统一性
数据库基础知识详解五:MySQL中的索引和其两种引擎、主从复制以及关系型/非关系型数据库
Dbaver cannot connect to the database. How to solve it?
Shang Silicon Valley smart campus - 6. Realization of administrator function
Detailed explanation of spark SQL underlying execution process
SAP UI5 應用開發教程之七十 - 如何使用按鈕控件觸發頁面路由跳轉試讀版
Qt网络与通信(TCP聊天室)
lightGBM专题2:基于pyspark在spark平台下lightgbm训练详解