当前位置:网站首页>Force buckle 1232 Dotted line

Force buckle 1232 Dotted line

2022-07-07 20:06:00 Tomorrowave

1232. Dotted line

Given an array coordinates , among coordinates[i] = [x, y] , [x, y] The abscissa is x、 Ordinate for y The point of . Please judge , Whether these points belong to the same line in the coordinate system .

Example 1:
Input :coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
Output :true

Ideas

Use the product of slope to do

Code section

class Solution:
    def checkStraightLine(self, coordinates: List[List[int]]) -> bool:
        a=coordinates[1][0]-coordinates[0][0]
        b=coordinates[1][1]-coordinates[0][1]

        for i in range(2,len(coordinates)):
            c = coordinates[i][0] - coordinates[0][0]
            d = coordinates[i][1] - coordinates[0][1]
            if (a * d - b * c != 0):
                return False
        return True
原网站

版权声明
本文为[Tomorrowave]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071753355895.html

随机推荐