
(x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)x1y2 + x2y3 + x3y1 - x1y3 - x2y1 - x3y2如上图所示
给定一个数组 points ,其中 points[i] = [xi, yi] 表示 X-Y 平面上的一个点,如果这些点构成一个 回旋镖 则返回 true 。
回旋镖 定义为一组三个点,这些点 各不相同 且 不在一条直线上 。
var isBoomerang = function(points) { // (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) - (points[2][0] - points[0][0]) * (points[1][1] - points[0][1]) !== 0
}; function isBoomerang(points: number[][]): boolean { // 萨吕法则
return (points[0][0] * points[1][1] + points[1][0] * points[2][1] + points[2][0] * points[0][1] - points[0][0] * points[2][1] - points[1][0] * points[0][1] - points[2][0] * points[1][1]) !== 0
}; func isBoomerang(points [][]int) bool {
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) - (points[2][0] - points[0][0]) * (points[1][1] - points[0][1]) != 0
} class Solution {
function isBoomerang($points) {
return ($points[0][0] * $points[1][1] + $points[1][0] * $points[2][1] + $points[2][0] * $points[0][1] - $points[0][0] * $points[2][1] - $points[1][0] * $points[0][1] - $points[2][0] * $points[1][1]) !== 0;
}
} class Solution {
public boolean isBoomerang(int[][] points) {
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) - (points[2][0] - points[0][0]) * (points[1][1] - points[0][1]) != 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[2][0] - points[0][0]) * (points[1][1] - points[0][1]) != 0 bool isBoomerang(int** points, int pointsSize, int* pointsColSize){
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) - (points[2][0] - points[0][0]) * (points[1][1] - points[0][1]) != 0;
} public class Solution {
public bool IsBoomerang(int[][] points) {
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) - (points[2][0] - points[0][0]) * (points[1][1] - points[0][1]) != 0;
}
} class Solution {
public:
bool isBoomerang(vector<vector<int>>& points) {
return (points[1][0] - points[0][0]) * (points[2][1] - points[0][1]) - (points[2][0] - points[0][0]) * (points[1][1] - points[0][1]) != 0;
}
};