当前位置:网站首页>[leetcode] day 48 - 1037 Effective boomerang

[leetcode] day 48 - 1037 Effective boomerang

2022-06-09 03:48:00 1 + 1= Wang

Title Description

 Insert picture description here

Their thinking

I didn't expect to encounter a pure mathematical problem .

So-called “ Effective boomerang ” It means that the three points given are not on the same straight line .

  • Two vectors can be calculated from three points
  • The three points are not on the same straight line , That is, the two vectors are not parallel , That is, cross multiplication is not 0.

Code implementation

class Solution {
    
    public boolean isBoomerang(int[][] points) {
    
    	// Calculate the first vector 
        int x1=points[1][0]-points[0][0],y1=points[1][1]-points[0][1]; 
        // Calculate the second vector  
        int x2=points[2][0]-points[0][0],y2=points[2][1]-points[0][1];  

		// The vector cross product is not 0
        return (x1*y2-x2*y1)!=0;
    }
}
原网站

版权声明
本文为[1 + 1= Wang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090338249912.html