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
Solution:
class Solution:
def isBoomerang(self, points: List[List[int]]) -> bool:
A, B, C = points
AB = ((A[0] - B[0])**2 + (A[1] - B[1])**2) ** 0.5
BC = ((B[0] - C[0])**2 + (B[1] - C[1])**2) ** 0.5
CA = ((C[0] - A[0])**2 + (C[1] - A[1])**2) ** 0.5
return (AB < CA + BC) and (BC < CA + AB) and (CA < AB + BC)
Explaination:
This problem can be interpreted as whether these 3 points can make a triangle. So we just need to check if the sum of length of two sides is always greater than the length of the third one.
网友评论