Skip to content

Commit e6261aa

Browse files
authored
Create Minimum Distance to the Target Element.java
1 parent 656c1a0 commit e6261aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int getMinDistance(int[] nums, int target, int start) {
3+
int minDistance = Integer.MAX_VALUE;
4+
for (int i = 0; i < nums.length; i++) {
5+
if (nums[i] == target) {
6+
minDistance = Math.min(minDistance, Math.abs(i - start));
7+
}
8+
}
9+
return minDistance;
10+
}
11+
}

0 commit comments

Comments
 (0)