zoukankan      html  css  js  c++  java
  • 1232. Check If It Is a Straight Line

    You are given an array coordinatescoordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.

    求所有点和第一个点的dx和dy,然后判断下dxi * dyj == dyi * dxj,如果打算求k和b的话得注意一下k=0和正无穷

    class Solution(object):
        def checkStraightLine(self, coordinates):
            """
            :type coordinates: List[List[int]]
            :rtype: bool
            """
            dx = coordinates[0][0] - coordinates[1][0]
            dy = coordinates[0][1] - coordinates[1][1]
            for i in range(2, len(coordinates), 1):
                point = coordinates[i]
                if dx * (point[1] - coordinates[0][1]) != dy * (point[0] - coordinates[0][0]):
                    return False
            return True
  • 相关阅读:
    排球教练积分程序
    排球积分程序
    排球积分程序
    14周总结
    本周总结
    排球计分规则
    我与计算机
    排球计分程序
    《如何成为一个高手》观后感
    十八周总结
  • 原文地址:https://www.cnblogs.com/whatyouthink/p/13255660.html
Copyright © 2011-2022 走看看