diff options
-rw-r--r-- | 1266/main.go | 37 | ||||
-rw-r--r-- | 9/main.go | 23 |
2 files changed, 60 insertions, 0 deletions
diff --git a/1266/main.go b/1266/main.go new file mode 100644 index 0000000..13cab76 --- /dev/null +++ b/1266/main.go @@ -0,0 +1,37 @@ +package main + +import "fmt" + +func min(a, b int) int { + if a < b { + return a + } + return b +} + +func abs(a int) int { + if a > 0 { + return a + } + return -a +} + +func minTimeToVisitAllPoints(points [][]int) int { + sum := 0 + for index, item := range points { + if index+1 < len(points) { + min_dist_x := abs(item[0] - points[index+1][0]) + min_dist_y := abs(item[1] - points[index+1][1]) + sum += min(min_dist_x, min_dist_y) + abs(min_dist_x-min_dist_y) + } + } + + return sum +} + +func main() { + points2 := [][]int{{3, 2}, {-2, 2}} + fmt.Println(minTimeToVisitAllPoints(points2)) + points := [][]int{{1, 1}, {3, 4}, {-1, 0}} + fmt.Println(minTimeToVisitAllPoints(points)) +} diff --git a/9/main.go b/9/main.go new file mode 100644 index 0000000..cc44567 --- /dev/null +++ b/9/main.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +func isPalindrome(x int) bool { + if x < 0 { + return false + } + var y int + for i := x; i > 0; i /= 10 { + y = y*10 + i%10 + fmt.Println(y) + } + return x == y +} + +func main() { + fmt.Println(isPalindrome(12345678)) + fmt.Println(isPalindrome(1234321)) + fmt.Println(isPalindrome(121)) + fmt.Println(isPalindrome(-121)) + fmt.Println(isPalindrome(10)) +} |