MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / isReflected

Function isReflected

tasks/356.go:7–33  ·  view source on GitHub ↗
(points [][]int)

Source from the content-addressed store, hash-verified

5}
6
7func isReflected(points [][]int) bool {
8 if len(points) < 2 {
9 return true
10 }
11 var min, max int
12 var mid float32
13 var m map[[2]int]bool
14 m = make(map[[2]int]bool)
15 min = points[0][0]
16 max = min
17 for i := 0; i < len(points); i++ {
18 if points[i][0] < min {
19 min = points[i][0]
20 } else if points[i][0] > max {
21 max = points[i][0]
22 }
23 m[[2]int{points[i][0], points[i][1]}] = true
24 }
25 mid = float32(min+max) / 2.0
26 for el := 0; el < len(points); el++ {
27 refX := int(2*mid) - points[el][0]
28 if _, ok := m[[2]int{refX, points[el][1]}]; !ok {
29 return false
30 }
31 }
32 return true
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected