mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-06-04 02:21:15 +08:00
routine
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user