+ [task#127424] add stack structure of getRegionInfo function.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user