Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 30, 2023
1 parent fba4aac commit 44e0bde
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// https://leetcode.com/problems/minimum-time-visiting-all-points

package main

import (
"fmt"
)

func minTimeToVisitAllPoints(points [][]int) int {
result := 0
for i, p := range points[1:] {
dx := abs(p[0] - points[i][0])
dy := abs(p[1] - points[i][1])
result += max(dx, dy)
}
return result
}

func abs(x int) int {
if x < 0 {
return -x
}
return x
}

func max(a, b int) int {
if a > b {
return a
}
return b
}

func main() {
points := [][]int{{1, 1}, {3, 4}, {-1, 0}}

fmt.Println(minTimeToVisitAllPoints(points))
}

0 comments on commit 44e0bde

Please sign in to comment.