We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 68c7aba commit 7429db9Copy full SHA for 7429db9
README.md
@@ -45,6 +45,8 @@ Step 2. Add the dependency
45
46
<summary>展开查看</summary>
47
48
+https://leetcode.cn/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate/
49
+
50
https://leetcode.cn/problems/leaf-similar-trees
51
52
https://leetcode.cn/problems/find-the-town-judge
find-nearest-point-that-has-the-same-x-or-y-coordinate/index.ts
@@ -0,0 +1,10 @@
1
+function nearestValidPoint(x: number, y: number, points: number[][]): number {
2
+ return points.reduce(
3
+ ([p, d], [a, b], i) =>
4
+ (x === a || y === b) && Math.abs(x - a) + Math.abs(y - b) < d
5
+ ? [i, Math.abs(x - a) + Math.abs(y - b)]
6
+ : [p, d],
7
+ [-1, Infinity],
8
+ )[0];
9
+}
10
+export default nearestValidPoint;
0 commit comments