Leetcode||35. Search Insert Position
来源:互联网 发布:linux java dlog.path 编辑:程序博客网 时间:2024/06/06 23:04
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Here are few examples.[1,3,5,6]
, 5 → 2[1,3,5,6]
, 2 → 1[1,3,5,6]
, 7 → 4[1,3,5,6]
, 0 → 0
class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ left = 0 right = len(nums) - 1 while left <= right: mid = (left + right) / 2 if target == nums[mid]: return mid elif target > nums[mid]: left = mid + 1 else: right = mid - 1 return left
阅读全文
0 0
- [LeetCode]35.Search Insert Position
- LeetCode --- 35. Search Insert Position
- LeetCode 35.Search Insert Position
- [Leetcode] 35. Search Insert Position
- LeetCode 35. Search Insert Position
- [leetcode] 35.Search Insert Position
- Leetcode 35. Search Insert Position
- 35. Search Insert Position LeetCode
- [LeetCode]35. Search Insert Position
- LeetCode 35. Search Insert Position
- 【LeetCode】35. Search Insert Position
- leetcode 35. Search Insert Position
- leetcode 35. Search Insert Position
- LeetCode 35. Search Insert Position
- LeetCode *** 35. Search Insert Position
- leetcode 35. Search Insert Position
- [LeetCode]35. Search Insert Position
- LeetCode 35. Search Insert Position
- Python爬虫--爬取赶集网的租房信息
- java servlet 导入 导出excel
- ElasticSearch5.x集群安装及测试
- 获取动态数据到echarts-折线图
- Web UI设计规范、设计细节、设计趋势
- Leetcode||35. Search Insert Position
- excel中插入图片
- java9 新特性
- C#中获取当前namespace和methodName(static上下文中也可用)
- Spring Boot集成Activiti工作流
- 深度学习的Attention模型
- canvas——js画多边形方法
- 分布式锁
- 嵌入式视频处理考虑(一)