mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
27 lines
1.1 KiB
HTML
27 lines
1.1 KiB
HTML
<p>Given an array of integers <code>nums</code> sorted in non-decreasing order, find the starting and ending position of a given <code>target</code> value.</p>
|
|
|
|
<p>If <code>target</code> is not found in the array, return <code>[-1, -1]</code>.</p>
|
|
|
|
<p>You must write an algorithm with <code>O(log n)</code> runtime complexity.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
<pre><strong>Input:</strong> nums = [5,7,7,8,8,10], target = 8
|
|
<strong>Output:</strong> [3,4]
|
|
</pre><p><strong>Example 2:</strong></p>
|
|
<pre><strong>Input:</strong> nums = [5,7,7,8,8,10], target = 6
|
|
<strong>Output:</strong> [-1,-1]
|
|
</pre><p><strong>Example 3:</strong></p>
|
|
<pre><strong>Input:</strong> nums = [], target = 0
|
|
<strong>Output:</strong> [-1,-1]
|
|
</pre>
|
|
<p> </p>
|
|
<p><strong>Constraints:</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> is a non-decreasing array.</li>
|
|
<li><code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code></li>
|
|
</ul>
|