Leetcode Note: Go - Minimum Time Visiting All Points
Minimum Time Visiting All Points - LeetCode
https://leetcode.com/problems/minimum-time-visiting-all-points/
- Go 言語で取り組んだメモ
回答
Minimum Time Visiting All Points - LeetCode
https://leetcode.com/problems/minimum-time-visiting-all-points/solutions/513894/golang-solution/
func minTimeToVisitAllPoints(points [][]int) int {
seconds := 0
for i, _ := range points {
if i == len(points) - 1 {
return seconds
}
dx := points[i+1][0] - points[i][0]
dy := points[i+1][1] - points[i][1]
dx = int(math.Abs(float64(dx)))
dy = int(math.Abs(float64(dy)))
if dx == dy {
seconds += int(math.Abs(float64(dx)))
} else {
if dx < dy {
seconds += int(math.Abs(float64(dy)))
} else {
seconds += int(math.Abs(float64(dx)))
}
}
}
return seconds
}