当前位置:网站首页>Force buckle 1037 Effective boomerang

Force buckle 1037 Effective boomerang

2022-07-07 01:08:00 Xiu Qiang

subject

Given an array points , among points[i] = [xi, yi] Express X-Y A point on the plane , If these points form a Boomerang Then return to true .

Boomerang Defined as a set of three points , These points Each are not identical And Not in a straight line .

source : Power button (LeetCode)
link :https://leetcode.cn/problems/valid-boomerang

Vector cross product

 Insert picture description here

Code

class Solution {
    public boolean isBoomerang(int[][] points) {
        //  Vector cross product 
return (points[0][0] - points[1][0]) * (points[1][1] - points[2][1]) - (points[0][1] - points[1][1]) * (points[1][0] - points[2][0]) != 0;
    }
}
原网站

版权声明
本文为[Xiu Qiang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061721404856.html