+ [task#128767] add calculation logic for maxLeft and minRight for the getMaxLeftAndMinRight.

This commit is contained in:
wangzemei
2024-10-08 14:51:33 +08:00
committed by 孙浩
parent 7dae9ebe4f
commit cb7b732340
+12
View File
@@ -175,7 +175,19 @@ function getMaxLeftAndMinRight(rows, start, h)
const rowLength = rows[Math.min(start + h - 1, rows.length - 1)]?.length || 0;
let left = rows[start][0][0] || 0;
let right = rowLength ? rows[Math.min(start + h - 1, rows.length - 1)][rowLength - 1][1] : 0;
for(let i = start; i < start + h; i++)
{
if(rows[i])
{
const rowData = rows[i];
const flattenedRow = flattenData(rowData);
const maxLeft = flattenedRow.reduce((max, item) => item[0] > max ? item[0] : max, -Infinity);
const minRight = flattenedRow.reduce((min, item) => item[1] < min ? item[1] : min, Infinity);
left = Math.max(left, maxLeft);
right = Math.min(right, minRight);
}
}
return {left, right};
}