LeetCode35.搜索插入位置

|--------------|
| LeetCode刷题记录 |

文章目录


📜题目描述

给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。

如果目标值不存在于数组中,返回它将会被按顺序插入的位置。

请必须使用时间复杂度为 O(log n) 的算法。

示例1

复制代码
输入: nums = [1,3,5,6], target = 5
输出: 2

示例2

复制代码
输入: nums = [1,3,5,6], target = 2
输出: 1

示例3:

复制代码
输入: nums = [1,3,5,6], target = 7
输出: 4

提示:

  • 1 <= nums.length <= 10^4
  • -10^4 <= numsi <= 10^4
  • nums 为 无重复元素 的 升序 排列数组
  • -10^4 <= target <= 10^4

💡解题思路

⌨C++代码

相关推荐
Pniubi5 小时前
01背包类问题-力扣416.分割等和子集
算法·leetcode·职场和发展
文丑颜不良啊15 小时前
LeetCode3041~3060题目解析
java·leetcode
文丑颜不良啊17 小时前
LeetCode3101~3120题目解析
java·leetcode
玄昌盛不会编程1 天前
LeetCode——2243. 计算字符串的数字和
java·算法·leetcode
文丑颜不良啊1 天前
LeetCode3061~3080题目解析
java·leetcode
文丑颜不良啊1 天前
LeetCode3081~3100题目解析
java·leetcode
文丑颜不良啊2 天前
LeetCode2981~3000题目解析
java·leetcode
文丑颜不良啊2 天前
LeetCode3001~3020题目解析
java·leetcode
Pniubi2 天前
力扣19 . 删除表的倒数第N个节点(栈)
算法·leetcode·职场和发展
文丑颜不良啊3 天前
LeetCode2761~2780题目解析
java·leetcode