当前位置:网站首页>LeetCode 593 Valid Squares [Math] HERODING's Road to LeetCode
LeetCode 593 Valid Squares [Math] HERODING's Road to LeetCode
2022-07-29 21:34:00 【HERODING23】

解题思路:
A math problem that is not very difficult,有好几种解决方法,The simplest is to directly determine whether it is a square or not,That is, only four sides are equal,And any two sides are parallel or perpendicular,A simpler way to judge is that any three points are a right triangle,代码如下:
class Solution {
public:
bool validSquare(vector<int>& p1, vector<int>& p2, vector<int>& p3, vector<int>& p4) {
return isRTriangle(p1, p2, p3) && isRTriangle(p1, p2, p4) && isRTriangle(p1, p3, p4) && isRTriangle(p2, p3, p4);
}
bool isRTriangle(vector<int>& p1, vector<int>& p2, vector<int>& p3) {
int l1 = (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
int l2 = (p1[0] - p3[0]) * (p1[0] - p3[0]) + (p1[1] - p3[1]) * (p1[1] - p3[1]);
int l3 = (p2[0] - p3[0]) * (p2[0] - p3[0]) + (p2[1] - p3[1]) * (p2[1] - p3[1]);
if(l1 > l2 && l2 == l3 && l1 == l2 + l3 ||
l2 > l1 && l1 == l3 && l2 == l1 + l3 ||
l3 > l1 && l1 == l2 && l3 == l1 + l2) {
return true;
}
return false;
}
};
边栏推荐
- es6语法使用默认参数和解构
- 小学弟问:程序员的工作是不是每天都是敲一天的代码呢?
- Cobaltstrike和BurpSuite桌面快捷配置
- MySQL - 设计游戏用户信息表
- Durable rules (persistent rules engine) learning notes
- Data visualization ---- web page displays temperature and humidity
- offsetwidth111[通俗易懂]
- 刘畊宏男孩女孩看过来!运动数据分析挖掘!(附全套代码和数据集)
- Samba server configuration (when a server is required)
- 促进二十一世纪创客教育的新发展
猜你喜欢

Data visualization ---- web page displays temperature and humidity

Setinel 原理简介

带你刷(牛客网)C语言百题(第四天)

conda虚拟环境 | install 与 list 问题

mos管闩锁效应理解学习

4. Implementation Guide for GET_ENTITYSET Method of SAP ABAP OData Service Data Provider Class

940. 不同的子序列 II

WeChat Mini Program 31 Subcontracting Mechanism

从实例学Kettle(一):获取股票行情数据

【无标题】
随机推荐
从专业角度分析国内创客教育发展
Is it safe to use the MD5 encrypted string to store the password?Hash algorithm you have to know
带你刷(牛客网)C语言百题(第四天)
offsetwidth111[通俗易懂]
WPF 实现抽屉菜单
240. Searching 2D Matrix II
Dry goods!Cooperative Balance in Federated Learning
es6语法使用默认参数和解构
核壳二氧化钛纳米颗粒修饰DNA|二氢杨梅素修饰DNA药物|相关介绍
指定宽度截取字符串
Samba服务器配置(什么情况下需要服务器)
378. 有序矩阵中第 K 小的元素
RedisJson 横空出世!
七个易犯的 IT 管理错误—以及如何避免
LeetCode 0144. 二叉树的前序遍历:二叉树必会题
LeetCode--单链表--146.LRU缓存
7 行代码搞崩溃 B 站,原因令人唏嘘!
SAP ABAP OData 服务 Data Provider Class 的 GET_ENTITYSET 方法实现指南试读版
940. 不同的子序列 II
用对象字面量或Map替代Switch/if语句