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 <= nums[i] <= 10^4
  • nums 为 无重复元素 的 升序 排列数组
  • -10^4 <= target <= 10^4

💡解题思路

⌨C++代码

相关推荐
刃神太酷啦12 小时前
聚焦 string:C++ 文本处理的核心利器--《Hello C++ Wrold!》(10)--(C/C++)
java·c语言·c++·qt·算法·leetcode·github
哎写bug的程序员1 天前
leetcode复盘(1)
算法·leetcode·职场和发展
qq_534452522 天前
【算法 day02】LeetCode 209.长度最小的子数组 | 59.螺旋矩阵II
java·算法·leetcode·职场和发展
dying_man2 天前
LeetCode--31.下一个排列
算法·leetcode
IC 见路不走2 天前
LeetCode 第75题:颜色分类
数据结构·算法·leetcode
Navigator_Z2 天前
LeetCode //C - 757. Set Intersection Size At Least Two
c语言·算法·leetcode
GalaxyPokemon2 天前
LeetCode - 704. 二分查找
数据结构·算法·leetcode
liuqun03192 天前
开心灿烂go开发面试题
算法·leetcode·golang
এ᭄画画的北北2 天前
力扣-279.完全平方数
数据结构·算法·leetcode
GalaxyPokemon2 天前
LeetCode - LCR 173. 点名
算法·leetcode·职场和发展