当前位置:网站首页>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;
}
};
边栏推荐
- LeetCode 0593. 有效的正方形
- 240. Searching 2D Matrix II
- 带你刷(牛客网)C语言百题(第四天)
- The difference between uri and url is simple to understand (what is the difference between uri and url)
- 干货!联邦学习中的合作均衡
- json-c实现json和结构体之间的相互转换
- What are the software development modes (software engineering development mode)
- 酷客导航助你商场轻松购物,业务办理不迷茫
- 分布式限流 redission RRateLimiter 的使用及原理
- 940. 不同的子序列 II
猜你喜欢
随机推荐
Durable rules(持久规则引擎) 学习小记
Baidu internship students late night fun: originally giant is this kind of life
About the choice of x86, x64, x86_64, ARM 64, ARM 32 when installing software
OneNote 教程,如何在 OneNote 中做笔记?
ALBERT:A Lite BERT for Self-supervised Learning of Language Representations
JUC Concurrent Programming Basics AQS
高通WLAN框架学习(31)-- Power save
7 行代码搞崩溃 B 站,原因令人唏嘘!
从实例学Kettle(一):获取股票行情数据
诺氟沙星-DNA复合物|半乳糖化脂质体-聚阳离子-DNA复合物|注意事项
[ACTF2020 新生赛]Exec 1
C# 窗体与子线程数据交互
240. Searching 2D Matrix II
荧光量子点修饰siRNA-QDs|纳米金修饰siRNA-Au(RNA修饰方式方法)
解析掌握现代化少儿编程实操能力
Setinel 原理简介
Durable rules (persistent rules engine) learning notes
C# WPF给综合实战项目加个帮助文档
Unity determines whether a string can be converted to float type
点击返回顶部









