Check If It Is a Straight Line LeetCode solution in Python

1
class Solution(object):
2
def checkStraightLine(self, coordinates):
3
"""
4
:type coordinates: List[List[int]]
5
:rtype: bool
6
"""
7
if len(coordinates) == 2:
8
return True
9

10
num = coordinates[1][1] - coordinates[0][1]
11
den = coordinates[1][0] - coordinates[0][0]
12

13
for i in range(2, len(coordinates)):
14
if num * (coordinates[i][0] - coordinates[0][0]) != den * (
15
coordinates[i][1] - coordinates[0][1]
16
):
17
return False
18

19
return True

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0