当前位置:网站首页>LeetCode 1037. 有效的回旋镖(向量叉乘)
LeetCode 1037. 有效的回旋镖(向量叉乘)
2022-06-12 11:46:00 【xylitolz】
题目

解法:向量叉乘
「三点各不相同且不在一条直线上」等价于「两个向量的叉乘结果不为零」:
v ⃗ 1 × v ⃗ 2 ≠ 0 \vec{v}_{1} \times \vec{v}_{2} \neq 0 v1×v2=0
两个向量的叉积等于零,则它们平行
算法流程:
- 由
points[0]和points[1]计算向量 v ⃗ 1 \vec{v}_{1} v1,由points[0]和points[2]计算向量 v ⃗ 2 \vec{v}_{2} v2 - 计算两向量的叉乘
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];
}
}
- 时间复杂度: O ( 1 ) O(1) O(1)
- 空间复杂度: O ( 1 ) O(1) O(1)
Reference
边栏推荐
猜你喜欢

QT based travel query and simulation system
![[the 11th national competition of Blue Bridge Cup single chip microcomputer]](/img/da/3c8a9efd5b28f67816f239531a0339.png)
[the 11th national competition of Blue Bridge Cup single chip microcomputer]

Analyze the implementation principle of the onion model, and connect the onion model in your own project

Index in MySQL show index from XXX the meaning of each parameter

First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware

Unity connect to Microsoft SQLSERVER database

C# 35. 选择默认网卡

VirtualBox virtual machine shut down due to abnormal system. The virtual machine startup item is missing

Pytoch notes

Windows10安装mysql-8.0.28-winx64
随机推荐
C# 37. Textbox scroll bar and multiline
ARM指令集之跳转指令
conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)
MySQL lock leak detection and defect filling
視頻分類的類間和類內關系——正則化
Inter class and intra class relations in video classification -- regularization
35. search insertion position
Blue Bridge Cup 2015 CA provincial competition (filling the pit)
UML series articles (31) architecture modeling - deployment diagram
文件夹目录结构自动生成
SSL引入原因及加密步骤
K58. Chapter 1 installing kubernetes V1.23 based on kubeadm -- cluster deployment
LLD monitored by ZABBIX
ARM指令集之伪指令
ARM指令集之Load/Store指令寻址方式(一)
Rich text editor copying pictures in word documents
套接字实现 TCP 通信流程
[database] SQLite version upgrade and downgrade
postman传入list
First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware