mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
27 lines
1.3 KiB
Markdown
27 lines
1.3 KiB
Markdown
<h2><a href="https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/">34. Find First and Last Position of Element in Sorted Array</a></h2><h3>Medium</h3><hr><div><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 class="example">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 class="example">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 class="example">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>
|
|
</div> |