当前位置:网站首页>LeetCode 1037. Effective boomerang (vector cross product)
LeetCode 1037. Effective boomerang (vector cross product)
2022-06-12 11:53:00 【xylitolz】
List of articles
subject

solution : Vector cross product
「 The three points are different and not in a straight line 」 Equivalent to 「 The cross product of two vectors is not zero 」:
v ⃗ 1 × v ⃗ 2 ≠ 0 \vec{v}_{1} \times \vec{v}_{2} \neq 0 v1×v2=0
The cross product of two vectors equals zero , Then they are parallel
Algorithm flow :
- from
points[0]andpoints[1]Calculate the vector v ⃗ 1 \vec{v}_{1} v1, frompoints[0]andpoints[2]Calculate the vector v ⃗ 2 \vec{v}_{2} v2 - Calculating the cross product of two vectors
class Solution {
public boolean isBoomerang(int[][] points) {
int[] v1 = {
points[0][0] - points[1][0], points[0][1] - points[1][1]};
int[] v2 = {
points[0][0] - points[2][0], points[0][1] - points[2][1]};
return v1[0] * v2[1] != v1[1] * v2[0];
}
}
- Time complexity : O ( 1 ) O(1) O(1)
- Spatial complexity : O ( 1 ) O(1) O(1)
Reference
边栏推荐
- 5g NR Protocol Learning - - ts38.211 downlink channel
- Manuscript manuscript format preparation
- Channel Shuffle类
- 35. search insertion position
- K53. Chapter 2 installing kubernetes v1.22 based on binary packages -- cluster deployment
- VirtualBox virtual machine shut down due to abnormal system. The virtual machine startup item is missing
- Pytorch笔记
- Lambda and filter, List 和 numpy array的索引,以及各种距离指标distance-metrics,拼接数组以及axis=0 and axis=1的区分
- PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)
- ARM指令集之数据处理指令寻址方式
猜你喜欢

Compiling Draco library on Windows platform

【深度学习基础】反向传播法(1)

ARM处理器模式与寄存器

7-5 复数四则运算

K52. Chapter 1: installing kubernetes v1.22 based on kubeadm -- cluster deployment

Rich text editor copying pictures in word documents

C# 35. Select default network card

Design of secure chat tool based on C #

LeetCode 1037. 有效的回旋镖(向量叉乘)

JS to load and display Excel files
随机推荐
35. search insertion position
IP address management
机器学习之线性模型
字节序(网络/主机)转换
SSL引入原因及加密步骤
QML学习 第一天
視頻分類的類間和類內關系——正則化
5g NR Protocol Learning - - ts38.211 downlink channel
Design of secure chat tool based on C #
Kubernetes cluster setup
FormatConversionTool. exe
创建Servlet项目
K52. Chapter 1: installing kubernetes v1.22 based on kubeadm -- cluster deployment
ioremap
6.6 separate convolution
UML series articles (31) architecture modeling - deployment diagram
6.6 分離卷積
FPGA Development - Hello_ World routine
PIP install in the CONDA environment cannot be installed into the specified CONDA environment (the default PIP installation location of the CONDA environment)
Unlimited growth, we will all go to the future | the 15th anniversary of the founding of InfoQ China