Skip to content

Commit a8e89e0

Browse files
authored
Add solution 593 in Javascript (#133)
1 parent b1d9899 commit a8e89e0

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ _If you like this project, please leave me a star._ ★
499499
|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
500500
|598|[Range Addition II](https://leetcode.com/problems/range-addition-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_598.java) | |Easy |
501501
|594|[Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_594.java) | |Easy | Array, HashMap
502-
|593|[Valid Square](https://leetcode.com/problems/valid-square/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_593.java) | |Medium | Math
502+
|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
503503
|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
504504
|591|[Tag Validator](https://leetcode.com/problems/tag-validator/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_591.java) | |Hard | Stack, String
505505
|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

Diff for: javascript/_593.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @param {number[]} p1
3+
* @param {number[]} p2
4+
* @param {number[]} p3
5+
* @param {number[]} p4
6+
* @return {boolean}
7+
*/
8+
9+
// const d12 = distanceSquare(p1, p2)
10+
// const d13 = distanceSquare(p1, p3)
11+
// const d14 = distanceSquare(p1, p4)
12+
// const d23 = distanceSquare(p2, p3)
13+
// const d24 = distanceSquare(p2, p4)
14+
// const d34 = distanceSquare(p3, p4)
15+
16+
// if (d12 === 0 || d13 === 0 || d14 === 0) return false
17+
18+
// // 1 2
19+
// // 3 4
20+
// if (d12 === d13 && d12 + d13 === d14 && d23 === d24 + d34) return true
21+
22+
// // 1 2
23+
// // 4 3
24+
// if (d12 === d14 && d12 + d14 === d13 && d24 === d34 + d23) return true
25+
26+
// // 1 3
27+
// // 4 2
28+
// if (d13 === d14 && d13 + d14 === d12 && d34 === d23 + d24) return true
29+
30+
var validSquare = function (p1, p2, p3, p4) {
31+
function distanceSquare(a, b) {
32+
return (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])
33+
}
34+
35+
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)
36+
37+
for (var i = 0; i < 3; i++) if (ds[i] !== ds[i + 1] || ds[i] === 0) return false
38+
39+
if (ds[4] === ds[5] && ds[4] === ds[0] * 2) return true
40+
41+
return false
42+
}

0 commit comments

Comments
 (0)