Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.18 KB

_1232. Check If It Is a Straight Line.md

File metadata and controls

45 lines (32 loc) · 1.18 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : September 25, 2024

Last updated : September 25, 2024


Related Topics : Array, Math, Geometry

Acceptance Rate : 39.64 %


Solutions

Python

class Solution:
    def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
        x, y = coordinates[0]
        x2, y2 = coordinates[1]
        if (x == x2 or y == y2) and (x != x2 or y != y2) :
            if x == x2 :
                return all(a == x2 for a, b in coordinates[2:])
            else :
                return all(b == y2 for a, b in coordinates[2:])

        delta = (y2 - y) / (x2 - x)

        try :
            return not any((delta != (y2 - y) / (x2 - x)) for x2, y2 in coordinates[2:])
        except ZeroDivisionError as zde :
            return False