Skip to content

Commit 413b1d2

Browse files
authored
feat: lc soluton,js for no. 0624
1 parent 2d4fe0d commit 413b1d2

File tree

1 file changed

+19
-0
lines changed
  • solution/0600-0699/0624.Maximum Distance in Arrays

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[][]} arrays
3+
* @return {number}
4+
*/
5+
var maxDistance = function(arrays) {
6+
let minVal = arrays[0][0];
7+
let maxVal = arrays[0][arrays[0].length - 1];
8+
let maxDist = 0;
9+
10+
for (let i = 1; i < arrays.length; i++) {
11+
const currentMin = arrays[i][0];
12+
const currentMax = arrays[i][arrays[i].length - 1];
13+
maxDist = Math.max(maxDist, Math.abs(currentMax - minVal), Math.abs(maxVal - currentMin));
14+
minVal = Math.min(minVal, currentMin);
15+
maxVal = Math.max(maxVal, currentMax);
16+
}
17+
18+
return maxDist;
19+
};

0 commit comments

Comments
 (0)