Valid Boomerang

easy geometry cross product math

Problem

Given an array points where points[i] = [xi, yi] represents three points on a plane, return true if these points form a boomerang. A boomerang is a set of three points that are all distinct and not in a straight line.

Inputpoints = [[1, 1], [2, 3], [3, 2]]
Outputtrue
The three points are distinct and not collinear, so they form a boomerang.

def is_boomerang(points):
    (x1, y1), (x2, y2), (x3, y3) = points
    cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)
    return cross != 0
function isBoomerang(points) {
  const [[x1, y1], [x2, y2], [x3, y3]] = points;
  const cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
  return cross !== 0;
}
class Solution {
    public boolean isBoomerang(int[][] points) {
        int x1 = points[0][0], y1 = points[0][1];
        int x2 = points[1][0], y2 = points[1][1];
        int x3 = points[2][0], y3 = points[2][1];
        int cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
        return cross != 0;
    }
}
bool isBoomerang(vector<vector<int>>& points) {
    int x1 = points[0][0], y1 = points[0][1];
    int x2 = points[1][0], y2 = points[1][1];
    int x3 = points[2][0], y3 = points[2][1];
    int cross = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
    return cross != 0;
}
Time: O(1) Space: O(1)