less than 1 minute read

1232. Check If It Is a Straight Line (easy)

class Solution:
    def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
        def acc(a, b):
            return (b[1] - a[1]) / (b[0] - a[0]) if b[0] != a[0] else math.inf
        
        n = len(coordinates)
        temp = acc(coordinates[0], coordinates[1])
        for i in range(n - 1):
            a, b = coordinates[i], coordinates[i + 1]
            if acc(a, b) != temp:
                return False
        
        return True