All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : September 25, 2024
Last updated : September 25, 2024
Related Topics : Array, Math, Geometry
Acceptance Rate : 39.64 %
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