Description
A 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:
- points.length == 3
- points[i].length == 2
- 0 <= points[i][j] <= 100
分析
题目的意思是:判断3个点是否在一个直线上。最简单的方法就是斜率y1/x2=y2/x2,公式变换位x1y2-x2y1=0,根据后面的公式判断一下就行了。
代码
class Solution:
def isBoomerang(self, points: List[List[int]]) -> bool:
a=points[0]
b=points[1]
c=points[2]
x1=b[0]-a[0]
y1=b[1]-a[1]
x2=c[0]-a[0]
y2=c[1]-a[1]
if(x1*y2-x2*y1!=0):
return True
return False