mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
56 lines
1.6 KiB
HTML
56 lines
1.6 KiB
HTML
<p>给定一个排序的整数数组 <code>nums</code> 和一个整数目标值<code> target</code> ,请在数组中找到 <code>target </code>,并返回其下标。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。</p>
|
|
|
|
<p>请必须使用时间复杂度为 <code>O(log n)</code> 的算法。</p>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = [1,3,5,6], target = 5
|
|
<strong>输出:</strong> 2
|
|
</pre>
|
|
|
|
<p><strong>示例 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = [1,3,5,6], target = 2
|
|
<strong>输出:</strong> 1
|
|
</pre>
|
|
|
|
<p><strong>示例 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = [1,3,5,6], target = 7
|
|
<strong>输出:</strong> 4
|
|
</pre>
|
|
|
|
<p><strong>示例 4:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = [1,3,5,6], target = 0
|
|
<strong>输出:</strong> 0
|
|
</pre>
|
|
|
|
<p><strong>示例 5:</strong></p>
|
|
|
|
<pre>
|
|
<strong>输入:</strong> nums = [1], target = 0
|
|
<strong>输出:</strong> 0
|
|
</pre>
|
|
|
|
<p> </p>
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>
|
|
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
|
|
<li><code>nums</code> 为<strong>无重复元素</strong>的<strong>升序</strong>排列数组</li>
|
|
<li><code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code></li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
|
|
<p><meta charset="UTF-8" />注意:本题与主站 35 题相同: <a href="https://leetcode-cn.com/problems/search-insert-position/">https://leetcode-cn.com/problems/search-insert-position/</a></p>
|