min_distance
to a large value (e.g., float('inf')
in Python).nums
using an index variable i
.nums[i]
, check if it equals the target
.i
and start
.min_distance
if the current distance is less than min_distance
.min_distance
as the result.