原题说明
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 == 3
points[i].length == 2
0 <= points[i][j] <= 100
解题思路
判断AB,AC斜率是否相同,如果相同则在一条线上
注意用乘法好过除法, 因为不用判断分母为0了。
面试时要考虑特殊情况,比如两个点重合是否算同线 (本题是distinct的点,所以不用考虑)
示例代码 (cpp)
1 | class Solution { |
示例代码 (java)
1 | class Solution { |
示例代码 (python)
1 | class Solution: |
复杂度分析
时间复杂度: O(1)
空间复杂度: O(1)
归纳总结
我们在Youtube上更新了视频讲解,欢迎关注!