1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
// @Title: 缀点成线 (Check If It Is a Straight Line)
// @Author: 15816537946@163.com
// @Date: 2021-01-17 12:02:14
// @Runtime: 0 ms
// @Memory: 3.6 MB
// math
func checkStraightLine(coordinates [][]int) bool {
	deltaX, deltaY := coordinates[0][0], coordinates[0][1]
	for _, p := range coordinates {
		p[0] -= deltaX
		p[1] -= deltaY
	}
	A, B := coordinates[1][1], -coordinates[1][0]
	for _, p := range coordinates[2:] {
		x, y := p[0], p[1]
		if A*x+B*y != 0 {
			return false
		}
	}
	return true
}