LeetCode 1037. 有效的回旋镖

回旋镖定义为一组三个点,这些点各不相同且不在一条直线上。

给出平面上三个点组成的列表,判断这些点是否可以构成回旋镖。

示例 1:

输入:[[1,1],[2,3],[3,2]]
输出:true

示例 2:

输入:[[1,1],[2,2],[3,3]]
输出:false

提示:

  1. points.length == 3
  2. points[i].length == 2
  3. 0 <= points[i][j] <= 100

思路:根据题意,三点不相同且不在一条直线上,所以,需要判断三点不重合且斜率不相等,由此,可以得出结果。

 1 bool isBoomerang(int** points, int pointsSize, int* pointsColSize){
 2     int x1,x2,y1,y2;
 3     if(points[0][0]==points[1][0]&&points[0][1]==points[1][1])
 4         return false;
 5     if(points[0][0]==points[2][0]&&points[0][1]==points[2][1])
 6         return false;
 7     if(points[1][0]==points[2][0]&&points[1][1]==points[2][1])
 8         return false;
 9     x1=points[0][0]-points[1][0];
10     x2=points[0][0]-points[2][0];
11     y1=points[0][1]-points[1][1];
12     y2=points[0][1]-points[2][1];
13     if(x1*y2-x2*y1==0){
14         return false;
15     }
16     return true;
17 }
原文地址:https://www.cnblogs.com/woju/p/12684790.html