diff --git a/26/04/1848.go b/26/04/1848.go new file mode 100644 index 0000000..65304f5 --- /dev/null +++ b/26/04/1848.go @@ -0,0 +1,20 @@ +package leetcode + +import "math" + +func abs(x int) int { + if x < 0 { + return -x + } + return x +} + +func getMinDistance(nums []int, target int, start int) int { + ans := math.MaxInt + for i, v := range nums { + if v == target { + ans = min(abs(i-start), ans) + } + } + return ans +}