Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add solution 593 in Javascript#133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fishercoder1534 merged 1 commit intofishercoder1534:masterfromltp88:js-593-solution
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -491,7 +491,7 @@ _If you like this project, please leave me a star._ ★
|599|[Minimum Index Sum of Two Lists](https://leetcode.com/problems/minimum-index-sum-of-two-lists/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_599.java) | |Easy | HashMap
|598|[Range Addition II](https://leetcode.com/problems/range-addition-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_598.java) | |Easy |
|594|[Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_594.java) | |Easy | Array, HashMap
|593|[Valid Square](https://leetcode.com/problems/valid-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_593.java) | |Medium | Math
|593|[Valid Square](https://leetcode.com/problems/valid-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_593.java), [Javascript](./javascript/_593.js) | |Medium | Math
|592|[Fraction Addition and Subtraction](https://leetcode.com/problems/fraction-addition-and-subtraction/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_592.java) | |Medium | Math
|591|[Tag Validator](https://leetcode.com/problems/tag-validator/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_591.java) | |Hard | Stack, String
|590|[N-ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_590.java) | |Easy| DFS, recursion
Expand Down
42 changes: 42 additions & 0 deletionsjavascript/_593.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
/**
* @param {number[]} p1
* @param {number[]} p2
* @param {number[]} p3
* @param {number[]} p4
* @return {boolean}
*/

// const d12 = distanceSquare(p1, p2)
// const d13 = distanceSquare(p1, p3)
// const d14 = distanceSquare(p1, p4)
// const d23 = distanceSquare(p2, p3)
// const d24 = distanceSquare(p2, p4)
// const d34 = distanceSquare(p3, p4)

// if (d12 === 0 || d13 === 0 || d14 === 0) return false

// // 1 2
// // 3 4
// if (d12 === d13 && d12 + d13 === d14 && d23 === d24 + d34) return true

// // 1 2
// // 4 3
// if (d12 === d14 && d12 + d14 === d13 && d24 === d34 + d23) return true

// // 1 3
// // 4 2
// if (d13 === d14 && d13 + d14 === d12 && d34 === d23 + d24) return true

var validSquare = function (p1, p2, p3, p4) {
function distanceSquare(a, b) {
return (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])
}

const ds = [distanceSquare(p1, p2), distanceSquare(p1, p3), distanceSquare(p1, p4), distanceSquare(p2, p3), distanceSquare(p2, p4), distanceSquare(p3, p4)].sort((a, b) => a - b)

for (var i = 0; i < 3; i++) if (ds[i] !== ds[i + 1] || ds[i] === 0) return false

if (ds[4] === ds[5] && ds[4] === ds[0] * 2) return true

return false
}

[8]ページ先頭

©2009-2025 Movatter.jp