1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48: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

37 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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>,返回&nbsp;<code>[-1, -1]</code></p>
<p>你必须设计并实现时间复杂度为&nbsp;<code>O(log n)</code>&nbsp;的算法解决此问题。</p>
<p>&nbsp;</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>示例&nbsp;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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup>&nbsp;&lt;= nums[i]&nbsp;&lt;= 10<sup>9</sup></code></li>
<li><code>nums</code>&nbsp;是一个非递减数组</li>
<li><code>-10<sup>9</sup>&nbsp;&lt;= target&nbsp;&lt;= 10<sup>9</sup></code></li>
</ul>