commit fc58c7b6ef7699ceaed49c0c827e5ec17fc7d08d
parent 9f2ea6325ffd66b6edc744b0ba5bca6ba905c0f0
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 14 Nov 2024 20:03:50 +0100
1 Random Problem
Diffstat:
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/0593.cpp b/Problems/0593.cpp
@@ -0,0 +1,23 @@
+class Solution {
+ static int distance(const vector<int> p1, const vector<int> p2) {
+ const int x = p1[0] - p2[0];
+ const int y = p1[1] - p2[1];
+
+ return x * x + y * y;
+ }
+
+ public:
+ bool validSquare(const vector<int> &p1, const vector<int> &p2, const vector<int> &p3,
+ const vector<int> &p4) const {
+ if (p1 == p2) return false;
+
+ int d[] = {
+ distance(p1, p2), distance(p1, p3), distance(p1, p4),
+ distance(p2, p3), distance(p2, p4), distance(p3, p4),
+ };
+
+ sort(d, d + 6);
+
+ return d[0] == d[1] && d[0] == d[2] && d[0] == d[3] && 2 * d[0] == d[4] && 2 * d[0] == d[5];
+ }
+};
diff --git a/README.md b/README.md
@@ -473,6 +473,7 @@ reference and a base for solving problems.
| 0589 | Easy | [N-ary Tree Preorder Traversal](Problems/0589.cpp) |
| 0590 | Easy | [N-ary Tree Postorder Traversal](Problems/0590.cpp) |
| 0592 | Medium | [Fraction Addition and Subtraction](Problems/0592.cpp) |
+| 0593 | Medium | [Valid Square](Problems/0593.cpp) |
| 0595 | Easy | [Big Countries](Problems/0595.cpp) |
| 0596 | Easy | [Classes More Than 5 Students](Problems/0596.cpp) |
| 0601 | Hard | [Human Traffic of Stadium](Problems/0601.cpp) |