Formatted question description: https://leetcode.ca/all/1037.html

1037. Valid Boomerang (Easy)

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:

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

Companies:
Google

Related Topics:
Math

Solution 1.

// OJ: https://leetcode.com/problems/valid-boomerang

// Time: O(1)
// Space: O(1)
class Solution {
public:
    bool isBoomerang(vector<vector<int>>& points) {
        return (points[0][1] - points[1][1]) * (points[0][0] - points[2][0]) != (points[0][1] - points[2][1]) * (points[0][0] - points[1][0]);
    }
};

Java

class Solution {
    public boolean isBoomerang(int[][] points) {
        int difX1 = points[1][0] - points[0][0], difY1 = points[1][1] - points[0][1];
        int difX2 = points[2][0] - points[1][0], difY2 = points[2][1] - points[1][1];
        return difX1 * difY2 != difX2 * difY1;
    }
}

All Problems

All Solutions