Posted on 2023-06-05 12:44
Uriel 阅读(31)
评论(0) 编辑 收藏 引用 所属分类:
闲来无事重切Leet Code 、
大水题
判断给出的所有点是否共线,水题
1 #1232
2 #Runtime: 45 ms (Beats 45.11%)
3 #Memory: 13.9 MB (Beats 29.35%)
4
5 class Solution(object):
6 def checkStraightLine(self, coordinates):
7 """
8 :type coordinates: List[List[int]]
9 :rtype: bool
10 """
11 eps = 1e-6
12 for k in range(2, len(coordinates)):
13 if coordinates[0][0] == coordinates[1][0]:
14 if coordinates[k][0] != coordinates[0][0]:
15 return False
16 else:
17 if abs(coordinates[0][0] - coordinates[k][0]) < eps or abs(1.0 * (coordinates[0][1] - coordinates[1][1]) / (coordinates[0][0] - coordinates[1][0]) - 1.0 * (coordinates[0][1] - coordinates[k][1]) / (coordinates[0][0] - coordinates[k][0])) > eps:
18 return False
19 return True