一.问题描述
A boomerang is a set of 3 points that are all distinct and not in a straight line.
Given a list of three points in the plane, return whether these points are a boomerang.
Example 1:
Input: [[1,1],[2,3],[3,2]]
Output: true
Example 2:
Input: [[1,1],[2,2],[3,3]]
Output: false
Note:
points.length == 3points[i].length == 20 <= points[i][j] <= 100
二.解题思路
在不在一条直线上其实就是斜率相等,主要就是注意一下/0的情况
三个点在一条竖线上或者有2个点相等都会出现/0的异常
三个点在一天横线和一条竖线比较容易处理我就直接单独拿出来判断
其他的就判断斜率是否相同了
更多leetcode算法题解法请关注我的专栏leetcode算法从零到结束或关注我
欢迎大家一起套路一起刷题一起ac
博客围绕LeetCode中判断三点是否为回旋镖的问题展开。指出判断三点不在一条直线上可通过判断斜率是否相等,但要注意除零异常,像三点在竖线或两点相等时会出现该情况,还提及横线和竖线情况单独判断,最后给出源码。
794

被折叠的 条评论
为什么被折叠?



