美文网首页
1232. 缀点成线

1232. 缀点成线

作者: Aedda | 来源:发表于2021-05-08 18:26 被阅读0次

    缀点成线

    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))
    

    相关文章

      网友评论

          本文标题:1232. 缀点成线

          本文链接:https://www.haomeiwen.com/subject/muxpdltx.html