Compute the cross product of the two vectors from the first point; a nonzero value means the triangle has positive area.
Complexity
O(1) time and O(1) space.
Check whether three two-dimensional points are distinct and non-collinear.
Compute the cross product of the two vectors from the first point; a nonzero value means the triangle has positive area.
O(1) time and O(1) space.
package main
func isBoomerang(points [][]int) bool {
return (points[1][0]-points[0][0])*(points[2][1]-points[0][1]) != (points[1][1]-points[0][1])*(points[2][0]-points[0][0])
}
class Solution:
def isBoomerang(self, points: list[list[int]]) -> bool:
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) != (points[1][1] - points[0][1]) * (points[2][0] - points[0][0])
function isBoomerang(points: number[][]): boolean {
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) !== (points[1][1] - points[0][1]) * (points[2][0] - points[0][0]);
}