LeetCode //C - 1037. Valid Boomerang
1037. Valid BoomerangGiven an array points wherep o i n t s [ i ] [ x i , y i ] points[i] [x_i, y_i]points[i][xi,yi]represents a point on the X-Y plane, returntrue if these points are a boomerang.A boomerang is a set of three points that are all distinct and not in a straight line.Example 1:Input:points [[1,1],[2,3],[3,2]]Output:trueExample 2:Input:points [[1,1],[2,2],[3,3]]Output:falseConstraints:points.length 3points[i].length 20 x i , y i 100 0 x_i, y_i 1000xi,yi100From: LeetCodeLink: 1036. Escape a Large MazeSolution:Ideas:A boomerang needs:3 distinct pointsnot collinearUsing the triangle-area / cross-product check:if cross product is 0, the 3 points are on the same lineotherwise, they form a boomerangBecause the problem guarantees exactly 3 points, this one check is enough.Code:boolisBoomerang(int**points,intpointsSize,int*pointsColSize){intx1points[0][0],y1points[0][1];intx2points[1][0],y2points[1][1];intx3points[2][0],y3points[2][1];/* Three points are on one line if the area of the triangle is 0: (x2 - x1) * (y3 - y1) (x3 - x1) * (y2 - y1) */return(x2-x1)*(y3-y1)!(x3-x1)*(y2-y1);}