Skip to content

Commit

Permalink
feat(lc): 每日一题
Browse files Browse the repository at this point in the history
  • Loading branch information
changshou83 committed Nov 30, 2022
1 parent 5af45c4 commit 90a3f43
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function nearestValidPoint(x: number, y: number, points: number[][]): number {
let res = -1;
let minDist = Infinity;
for(let i = 0; i < points.length; i++) {
const [_x, _y] = points[i];
if(_x === x || _y === y) {
const dist = Math.abs(x - _x) + Math.abs(y - _y);
if(dist < minDist) {
minDist = dist;
res = i;
}
}
}
return res;
};

0 comments on commit 90a3f43

Please sign in to comment.