1848. Minimum Distance to the Target Element
Algorithm Steps
- Iterate
numsand store the indices of all elements that satisfynums[i] == targetinpos - Iterate
pos, calculate the minimumabs(i - start)
Complexity Analysis
Time complexity: O(n)
Space complexity: O(n)
C++ Code
|
|
Python Code
|
|
Go Code
|
|
JavaScript Code
|
|