35. 搜索插入位置
https://leetcode-cn.com/problems/search-insert-position/
题目描述
方法 1:二分查找
思路
用二分法找到目标值,或者找到大于目标值的数字中最左边的那个,返回下标。
复杂度分析
时间复杂度:$O(logN)$,N 是数组长度。
空间复杂度:$O(1)$。
代码
JavaScript Code
Last updated
Was this helpful?
https://leetcode-cn.com/problems/search-insert-position/
用二分法找到目标值,或者找到大于目标值的数字中最左边的那个,返回下标。
时间复杂度:$O(logN)$,N 是数组长度。
空间复杂度:$O(1)$。
JavaScript Code
Last updated
Was this helpful?