35.Search-Insert-Position

35. Search Insert Position

้ข˜็›ฎๅœฐๅ€

http://www.lintcode.com/problem/search-insert-position/descriptionarrow-up-right

https://www.jiuzhang.com/solutions/search-insert-position/arrow-up-right

้ข˜็›ฎๆ่ฟฐ

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.

Example
[1,3,5,6], 5 โ†’ 2

[1,3,5,6], 2 โ†’ 1

[1,3,5,6], 7 โ†’ 4

[1,3,5,6], 0 โ†’ 0

Challenge
O(log(n)) time

ไปฃ็ 

Appraoch 1: Find the first position

Last updated