Skip to main content

1162.js

/** ------------------------------------------------------------------------------
*
* 2023-02-10
* 1162. As Far from Land as Possible
* https://leetcode.com/problems/as-far-from-land-as-possible/
*
------------------------------------------------------------------------------ */
/**
* @param {number[][]} grid
* @return {number}
*/
var maxDistance = function (grid) {
let res = -1,
n = grid.length;
map = [[], []];

for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
const p = grid[i][j];
console.log("p", p);
map[p].push([i, j]);
}
}

console.log("map", map);
console.log("map[0]", map[0]);
console.log("map[1]", map[1]);
};

const grid = [
[1, 0, 0],
[0, 0, 0],
[0, 0, 0],
];
// const grid = [[1, 0, 1],[0, 0, 0],[1, 0, 1],];
console.log(maxDistance(grid));

const distance = (p0, p1) => {
const x0 = p0[0],
x1 = p1[0],
y0 = p0[0],
y1 = p0[1];
let d = 0;

if (x0 > x1) {
d += x0 - x1;
} else {
d += x1 - x0;
}

if (y0 > y1) {
d += y0 - y1;
} else {
d += y1 - y0;
}
console.log("d: ", d);
return d;
};