1848. Minimum Distance to the Target Element
Last updated
Last updated
/**
* Time complexity :
* Space complexity :
*/
class Solution {
public int getMinDistance(int[] nums, int target, int start) {
int result = Integer.MAX_VALUE;
for(int i = 0; i < nums.length; i++) {
if(nums[i] == target && Math.abs(i-start) < result) {
result = Math.abs(i-start);
}
}
return result;
}
}