Skip to content

Commit 0e8724f

Browse files
add 1848
1 parent 88dd14a commit 0e8724f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1848|[Minimum Distance to the Target Element](https://leetcode.com/problems/minimum-distance-to-the-target-element/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1848.java) ||Easy|Array|
1112
|1845|[Seat Reservation Manager](https://leetcode.com/problems/seat-reservation-manager/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1845.java) ||Medium|Heap, Design|
1213
|1844|[Replace All Digits with Characters](https://leetcode.com/problems/replace-all-digits-with-characters/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1844.java) ||Easy|String|
1314
|1837|[Sum of Digits in Base K](https://leetcode.com/problems/sum-of-digits-in-base-k/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1837.java) ||Easy|Math, Bit Manipulation|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1848 {
4+
public static class Solution1 {
5+
public int getMinDistance(int[] nums, int target, int start) {
6+
int result = 0;
7+
int minDiff = Integer.MAX_VALUE;
8+
for (int i = 0; i < nums.length; i++) {
9+
if (nums[i] == target) {
10+
if (Math.abs(start - i) < minDiff) {
11+
minDiff = Math.abs(start - i);
12+
result = minDiff;
13+
}
14+
}
15+
}
16+
return result;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)