Leetcode Note: Go - Check if It Is a Straight Line

Check If It Is a Straight Line - LeetCode
https://leetcode.com/problems/check-if-it-is-a-straight-line/

  • Go 言語で取り組んだメモ

回答

Check If It Is a Straight Line - LeetCode
https://leetcode.com/problems/check-if-it-is-a-straight-line/solutions/1176782/golang-solution-100-100-with-explanation/?orderBy=most_votes&languageTags=golang

func checkStraightLine(coordinates [][]int) bool {
    x0, x1 := coordinates[0][0], coordinates[1][0]
    y0, y1 := coordinates[0][1], coordinates[1][1]

    for i := 1; i < len(coordinates); i++ {
        x2, y2 := coordinates[i][0], coordinates[i][1]
        if (x1 - x0) * (y2 - y1) != (y1 - y0) * (x2 - x1) {
            return false
        }
    }
    return true
}