1232. 缀点成线
2021-05-08 本文已影响0人
Aedda
缀点成线
class Solution:
@staticmethod
def checkStraightLine(coordinates: list):
'''
默认x差 * y差 == 默认y差 * x差 全为ture 则为直线
'''
x_subtract = coordinates[1][0] - coordinates[0][0]
y_subtract = coordinates[1][1] - coordinates[0][1]
return all(x_subtract * (y - coordinates[0][1]) == y_subtract * (x - coordinates[0][0]) for x, y in coordinates)
coordinates = [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]
print(Solution().checkStraightLine(coordinates))