LeetCode——Search Insert Position
来源:互联网 发布:python获取当前路径 编辑:程序博客网 时间:2024/05/16 02:33
Search Insert Position
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
public class Solution { public int searchInsert(int[] A, int target) { int len = A.length; int start =0; int end = len-1; int index =0; for(;;) { if(start ==end) { if(A[end]<target)return end+1; else return end; } index=(start+end)/2; if(A[index]<target) { start = index+1; } else if(A[index]>target){ end =index; } else{ return index; } } }}
0 0
- LeetCode—Search Insert Position
- LeetCode——Search Insert Position
- LeetCode——Search Insert Position
- leetcode 035 —— Search Insert Position
- leetcode——Search Insert Position
- leetcode——Search Insert Position 二分查找 binary search
- LeetCode: Search Insert Position
- LeetCode Search Insert Position
- [Leetcode] Search Insert Position
- LeetCode : Search Insert Position
- [LeetCode] Search Insert Position
- [Leetcode] Search Insert Position
- [LeetCode]Search Insert Position
- [LeetCode] Search Insert Position
- LeetCode-Search Insert Position
- LeetCode - Search Insert Position
- LeetCode | Search Insert Position
- Leetcode: Search Insert Position
- lua ide
- 求出100之类的素数;
- linux命令之ldd
- 第12周项目2-分离一个整数的各位数
- 用javabean封装xml文档数据
- LeetCode——Search Insert Position
- webrtc系列专题之trickle ice
- 【C语言疯狂讲义】(十二)C语言二维数组
- 哈希表(初步实现)
- windows程序设计之捕获鼠标
- MVC入门(一)——什么是MVC及其处理方式
- UVA10254 - The Priest Mathematician(找规律)
- 数据类型和基本运算第一天
- 可以让图标随心所遇的变色