34. Find First and Last Position of Element in Sorted Array Medium
1/**
2 * [34] Find First and Last Position of Element in Sorted Array
3 *
4 * Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.
5 * If target is not found in the array, return [-1, -1].
6 * You must write an algorithm with O(log n) runtime complexity.
7 *
8 * Example 1:
9 * Input: nums = [5,7,7,8,8,10], target = 8
10 * Output: [3,4]
11 * Example 2:
12 * Input: nums = [5,7,7,8,8,10], target = 6
13 * Output: [-1,-1]
14 * Example 3:
15 * Input: nums = [], target = 0
16 * Output: [-1,-1]
17 *
18 * Constraints:
19 *
20 * 0 <= nums.length <= 10^5
21 * -10^9 <= nums[i] <= 10^9
22 * nums is a non-decreasing array.
23 * -10^9 <= target <= 10^9
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
29// discuss: https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn search_range(nums: Vec<i32>, target: i32) -> Vec<i32> {
35 vec![]
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_34() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.