lintcode python 容易 60.搜索插入位置
来源:互联网 发布:泗洪淘宝拍卖行 编辑:程序博客网 时间:2024/06/05 09:22
60.搜索插入位置
给定一个排序数组和一个目标值,如果在数组中找到目标值则返回索引。如果没有,返回到它将会被按顺序插入的位置。
你可以假设在数组中无重复元素。
样例:
[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: """ @param: A: an integer sorted array @param: target: an integer to be inserted @return: An integer """ def searchInsert(self, A, target): # write your code here if A is None: return None if A == []: return 0 n = len(A) if A[0] >= target: return 0 if A[n - 1] < target: return n for i in range(n): while(A[i] == target): return i for i in range(n - 1): if target > A[i] and target < A[i + 1]: return i + 1
阅读全文
1 0
- lintcode python 容易 60.搜索插入位置
- LintCode : 搜索插入位置
- lintcode ----搜索插入位置
- LintCode : 插入搜索位置
- Lintcode 搜索插入位置
- lintcode:搜索插入位置
- Lintcode搜索插入位置
- lintCode 搜索插入位置
- 【lintcode笔记】搜索插入位置
- LintCode 60 搜索插入位置
- 60.Search Insert Position-搜索插入位置(容易题)
- 【LintCode】Search Insert Position 搜索插入位置
- 60. 搜索插入位置
- LintCode 二分法查找, 搜索插入位置 和 二维矩阵
- lintcode&九章算法——No.60 搜索插入位置 ? 待解决
- 题目:搜索插入位置
- 搜索插入位置
- 搜索插入位置
- 某公司网络搭建
- Android初级开发(九)——网络交互—解析XML格式数据
- ie浏览器下右侧滚动条会遮挡部分内容
- Ubuntu命令学习
- JavaScript 学习笔记
- lintcode python 容易 60.搜索插入位置
- 24BY748步进电机的使用手册
- 基于TensorFlow实现卷积神经网络 1
- 哈哈哈
- jQuery甘特图插件jQuery.Gantt
- Oracle gateways连接SqlServer
- HTML与CSS
- Android GridView设置item的高度与宽度相等、GridView条目宽高相同
- 高并发解决方案