Valid Boomerang — LeetCode 1037 Python Solution
- Problem
- #1037
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang. A boomerang is a set of three points that are all distinct and not in a straight line.
Example
- Input
- points = [[1,1],[2,3],[3,2]]
- Output
- true
Python solution
class Solution:
def isBoomerang(self, points: List[List[int]]) -> bool:
(x1, y1), (x2, y2), (x3, y3) = points
return (y2 - y1) * (x3 - x2) != (y3 - y2) * (x2 - x1)Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) or O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 1037. Valid Boomerang is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math and Geometry.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1037. Valid Boomerang?
- LeetCode 1037. Valid Boomerang is rated Easy on LeetCode.
- What topics does LeetCode 1037. Valid Boomerang cover?
- LeetCode 1037. Valid Boomerang is tagged Geometry, Array and Math on LeetCode.