+ [task#127424] add stack structure of getRegionInfo function.

This commit is contained in:
wangzemei
2024-09-05 16:39:53 +08:00
committed by 刘刚
parent 5936ebdc5c
commit 33d8cbb93d
+15
View File
@@ -97,5 +97,20 @@ function getRegionInfo(pixels, visited, x, y, width, height)
{
const region = {area: 0, rows: []};
/* 创建栈数据结构。*/
/* Create a stack data structure.*/
const stack = [[x, y]];
while(stack.length > 0)
{
const [currentX, currentY] = stack.pop();
const index = (currentY * width * 4) + (currentX * 4);
if(pixels[index] === 255 && !visited[currentY + ',' + currentX])
{
visited[currentY + ',' + currentX] = true;
region.area++;
}
}
return region;
}