Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How LeetCode finds the first and last positions of elements in a sorted array

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how LeetCode finds the first and last location of elements in the sorted array. It is very detailed and has certain reference value. Interested friends must finish reading it.

First, find the first and last position 1 of the element in the sorted array, problem description

Given an array of integers nums in ascending order, and a target value target. Find out the start and end positions of the given target value in the array.

If the target value target does not exist in the array, return [- 1,-1].

2, example description example 1:

Input: nums = [5, 7, 7, 8, 8, 10], target = 8

Output: [3pd4]

Example 2:

Input: nums = [5, 7, 7, 8, 8, 10], target = 6

Output: [- 1mai Mui 1]

Example 3:

Input: nums = [], target = 0

Output: [- 1mai Mui 1]

Tip:

0

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report