题目如下:

boomerang is a set of 3 points that are all distinct and not in a straight line.

Given a list of three points in the plane, return whether these points are a boomerang.

 

Example 1:

Input: [[1,1],[2,3],[3,2]]
Output: true

Example 2:

Input: [[1,1],[2,2],[3,3]]
Output: false

 

Note:

  1. points.length == 3
  2. points[i].length == 2
  3. 0 <= points[i][j] <= 100

解题思路:本题就是判断三点是否在一条直线上,判断的方法也很简单,任意从这三个点中选取两组点对,如果这两组的点对的斜率相同,则在同一直线上。

代码如下:

class Solution(object):
    def isBoomerang(self, points):
        """
        :type points: List[List[int]]
        :rtype: bool
        """
        return (points[0][1]-points[1][1]) * (points[1][0]-points[2][0]) \
               != (points[0][0]-points[1][0]) * (points[1][1]-points[2][1])

 

相关文章:

  • 2021-07-09
  • 2021-05-28
  • 2022-01-30
  • 2022-02-17
  • 2022-02-20
  • 2021-08-19
  • 2021-06-22
  • 2021-12-23
猜你喜欢
  • 2021-06-08
  • 2021-10-08
  • 2021-08-11
  • 2022-12-23
  • 2021-09-11
  • 2021-08-30
  • 2021-09-14
相关资源
相似解决方案