1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/在排序数组中查找元素的第一个和最后一个位置 [find-first-and-last-position-of-element-in-sorted-array].html
2022-03-29 12:43:11 +08:00

41 lines
1.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个按照升序排列的整数数组 <code>nums</code>,和一个目标值 <code>target</code>。找出给定目标值在数组中的开始位置和结束位置。</p>
<p>如果数组中不存在目标值 <code>target</code>,返回 <code>[-1, -1]</code></p>
<p><strong>进阶:</strong></p>
<ul>
<li>你可以设计并实现时间复杂度为 <code>O(log n)</code> 的算法解决此问题吗?</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [<code>5,7,7,8,8,10]</code>, target = 8
<strong>输出:</strong>[3,4]</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [<code>5,7,7,8,8,10]</code>, target = 6
<strong>输出:</strong>[-1,-1]</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [], target = 0
<strong>输出:</strong>[-1,-1]</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
<li><code>nums</code> 是一个非递减数组</li>
<li><code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code></li>
</ul>