|
1 | 1 | [#0034-find-first-and-last-position-of-element-in-sorted-array]
|
2 |
| -= 34. Find First and Last Position of Element in Sorted Array |
| 2 | += 34. 在排序数组中查找元素的第一个和最后一个位置 |
3 | 3 |
|
4 |
| -{leetcode}/problems/find-first-and-last-position-of-element-in-sorted-array/[LeetCode - Find First and Last Position of Element in Sorted Array^] |
| 4 | +https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/[LeetCode - 34. 在排序数组中查找元素的第一个和最后一个位置 ^] |
5 | 5 |
|
6 |
| -Given an array of integers `nums` sorted in ascending order, find the starting and ending position of a given `target` value. |
| 6 | +给你一个按照非递减顺序排列的整数数组 `nums`,和一个目标值 `target`。请你找出给定目标值在数组中的开始位置和结束位置。 |
7 | 7 |
|
8 |
| -Your algorithm's runtime complexity must be in the order of _O_(log _n_). |
| 8 | +如果数组中不存在目标值 `target`,返回 `[-1, -1]`。 |
9 | 9 |
|
10 |
| -If the target is not found in the array, return `[-1, -1]`. |
| 10 | +你必须设计并实现时间复杂度为 stem:[log_2n] 的算法解决此问题。 |
11 | 11 |
|
12 |
| -*Example 1:* |
| 12 | +*示例 1:* |
13 | 13 |
|
14 | 14 | [subs="verbatim,quotes,macros"]
|
15 | 15 | ----
|
16 |
| -*Input:* nums = [`5,7,7,8,8,10]`, target = 8 |
17 |
| -*Output:* [3,4] |
| 16 | +输入:nums = [5,7,7,8,8,10], target = 8 |
| 17 | +输出:[3,4] |
18 | 18 | ----
|
19 | 19 |
|
20 |
| -*Example 2:* |
| 20 | +*示例 2:* |
21 | 21 |
|
22 | 22 | [subs="verbatim,quotes,macros"]
|
23 | 23 | ----
|
24 |
| -*Input:* nums = [`5,7,7,8,8,10]`, target = 6 |
25 |
| -*Output:* [-1,-1] |
| 24 | +输入:nums = [5,7,7,8,8,10], target = 6 |
| 25 | +输出:[-1,-1] |
26 | 26 | ----
|
27 | 27 |
|
| 28 | +*示例 3:* |
| 29 | + |
| 30 | +[subs="verbatim,quotes,macros"] |
| 31 | +---- |
| 32 | +输入:nums = [], target = 0 |
| 33 | +输出:[-1,-1] |
| 34 | +---- |
| 35 | + |
| 36 | +*提示:* |
| 37 | + |
| 38 | +* `+0 <= nums.length <= 10+`^`+5+`^ |
| 39 | +* `-10`^`9`^`+<= nums[i] <= 10+`^`9`^ |
| 40 | +* `nums` 是一个非递减数组 |
| 41 | +* `-10`^`9`^`+<= target <= 10+`^`9`^ |
| 42 | +
|
28 | 43 | == 思路分析
|
29 | 44 |
|
30 | 45 | 可以直接使用二分查找,搜索两次。
|
31 | 46 |
|
32 | 47 | [[src-0034]]
|
| 48 | +[tabs] |
| 49 | +==== |
| 50 | +一刷:: |
| 51 | ++ |
| 52 | +-- |
33 | 53 | [{java_src_attr}]
|
34 | 54 | ----
|
35 | 55 | include::{sourcedir}/_0034_FindFirstAndLastPositionOfElementInSortedArray.java[tag=answer]
|
36 | 56 | ----
|
| 57 | +-- |
| 58 | +
|
| 59 | +二刷:: |
| 60 | ++ |
| 61 | +-- |
| 62 | +[{java_src_attr}] |
| 63 | +---- |
| 64 | +include::{sourcedir}/_0034_FindFirstAndLastPositionOfElementInSortedArray_2.java[tag=answer] |
| 65 | +---- |
| 66 | +-- |
| 67 | +==== |
37 | 68 |
|
38 | 69 | == 参考资料
|
39 | 70 |
|
|
0 commit comments