Title: #593 - Valid Square - LeetCode JavaScript Solutions
Open Graph Title: #593 - Valid Square - LeetCode JavaScript Solutions
X Title: #593 - Valid Square - LeetCode JavaScript Solutions
Description: Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square. The coordinate of a p...
Open Graph Description: Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square. The coordinate of a p...
X Description: Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square. The coordinate of a p...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/valid-square
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/valid-square","name":"#593 - Valid Square - LeetCode JavaScript Solutions","description":"Given the coordinates of four points in 2D space p1, p2, p3 and p4, return true if the four points construct a square. The coordinate of a p...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} p1\n * @param {number[]} p2\n * @param {number[]} p3\n * @param {number[]} p4\n * @return {boolean}\n */\nvar validSquare = function(p1, p2, p3, p4) {\n const helper = (a, b) => (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2;\n const points = [p1, p2, p3, p4];\n const set = new Set();\n\n for (let i = 0; i < 4; i++) {\n for (let j = i + 1; j < 4; j++) {\n const d = helper(points[i], points[j]);\n if (!d) {\n return false;\n }\n set.add(d);\n }\n }\n\n return set.size === 2;\n};","keywords":"LeetCode 593, #593 - Valid Square, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/valid-square |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/valid-square/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0593-valid-square.js |
| Math | https://leetcodejavascript.com/tags/math |
| Geometry | https://leetcodejavascript.com/tags/geometry |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow