当前位置:网站首页>[binary search - simple] sword finger offer II 068 Find insertion location
[binary search - simple] sword finger offer II 068 Find insertion location
2022-04-21 15:11:00 【Caicai 2022】
【 subject 】
【 Example 】
Example 1:
Input : nums = [1,3,5,6], target = 5
Output : 2
Example 2:
Input : nums = [1,3,5,6], target = 2
Output : 1
Example 3:
Input : nums = [1,3,5,6], target = 7
Output : 4
Example 4:
Input : nums = [1,3,5,6], target = 0
Output : 0
Example 5:
Input : nums = [1], target = 0
Output : 0
【 Tips 】
1 <= nums.length <= 104
-104 <= nums[i] <= 104
nums Arrange the array in ascending order without repeating elements
-104 <= target <= 104
【 Code 】
Execution time :32 ms, In all Python3 Defeated in submission 87.47% Users of
Memory consumption :15.6 MB, In all Python3 Defeated in submission 34.53% Users of
Pass the test case :62 / 62
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
left, right = 0, len(nums)
while left < right:
mid = left + (right - left) // 2
if nums[mid] < target:
left = mid + 1
else:
right = mid
return left
版权声明
本文为[Caicai 2022]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211507333050.html
边栏推荐
猜你喜欢

Mysql 执行流程

scala安装及环境配置

Cousin node-c language of binary tree

尚硅谷智慧校园 —— 6、管理员功能实现

数字化时代,SaaS软件如何成为国产化替代的轻骑兵?

二叉树的堂兄弟节点-c语言

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

SAP ui5 application development tutorial 70 - how to use button controls to trigger page routing jump trial version

数据库基础知识详解五:MySQL中的索引和其两种引擎、主从复制以及关系型/非关系型数据库

突然掉电,为啥MySQL也不会丢失数据?(收藏)
随机推荐
Dry goods | environmental problems or chronic difficulties in testing? It's easy to do it in two steps
干货 | 录制你的第一个web 自动化测试用例
Qt网络与通信(TCP聊天室)
How to call uniCloud cloud storage in Nodejs project to upload middle note files
SAP ui5 application development tutorial 70 - how to use button controls to trigger page routing jump trial version
SAP UI5 應用開發教程之七十 - 如何使用按鈕控件觸發頁面路由跳轉試讀版
Service中是如何产生ANR的?
Storage system and memory
干货 | 环境问题还是测试的老大难?两个步骤轻松搞定
存储系统及存储器
【二分查找-简单】278. 第一个错误的版本
智慧公安二维码定位报警系统开发 移动警务app
C language preprocessing problem
武汉科技大学C语言上机实验题(第一第二第三部分)
【历史上的今天】4 月 21 日:微处理器先驱诞生;Winamp 发布;COPPA 正式生效
归纳偏置/归纳偏差/inductive bias
Insecte dans Hill
Mysql数据库(2)
虫子 插入 希尔
SAP UI5 应用开发教程之七十 - 如何使用按钮控件触发页面路由跳转试读版