Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Lintcode14 First Position of Target Solution problem solution

Shulou Source: shulou.com Published: 2022-06-03 04:20:43 10月26日 Update

[topic description]

For a given sorted array (ascending order) and a target number, find the first index of this number in O (log n) time complexity.

If the target number does not exist in the array, return-1.

Given a sorted array of integers (ascending order) and an integer target to find, use O (logn) time to find the first subscript of target (starting at 0), and return-1 if target does not exist in the array.

[topic link]

Http://www.lintcode.com/en/problem/first-position-of-target/

[topic Analysis]

This topic requires the complexity of O (logn), which is sorted array again, so let's do dichotomy without saying much. Note that first position of target is required, so when (array [mid] = = target), the operation is end = mid.

After finding the first target in dichotomy, query the first target one by one

Use binary search in the whole process.

[answer link]

Http://www.jiuzhang.com/solutions/first-position-of-target/

Tags: Questions arrays integers links complexity subscript dichotomy whole process ascending order again complexity time time first time answer sort query problem solution Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn macOS Huawei Redmi