mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
24 lines
343 B
Go
24 lines
343 B
Go
package leetcode
|
|
|
|
func minTimeToVisitAllPoints(points [][]int) int {
|
|
res := 0
|
|
for i := 1; i < len(points); i++ {
|
|
res += max(abs(points[i][0]-points[i-1][0]), abs(points[i][1]-points[i-1][1]))
|
|
}
|
|
return res
|
|
}
|
|
|
|
func max(a int, b int) int {
|
|
if a > b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func abs(a int) int {
|
|
if a > 0 {
|
|
return a
|
|
}
|
|
return -a
|
|
}
|