Skip to content

Commit 3cb9b97

Browse files
authored
Also deduplicate the other occurrence
1 parent cf34946 commit 3cb9b97

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: Recursive/FloodFill.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ function breadthFirstFill(
9898
rgbData[currentLocation[0]][currentLocation[1]] = replacementColor
9999

100100
for (let i = 0; i < neighbors.length; i++) {
101-
const x = currentLocation[0] + neighbors[i][0]
102-
const y = currentLocation[1] + neighbors[i][1]
103-
if (x >= 0 && x < rgbData.length && y >= 0 && y < rgbData[0].length) {
104-
queue.push([x, y])
101+
const newLocation = [
102+
currentLocation[0] + neighbors[i][0],
103+
currentLocation[1] + neighbors[i][1]
104+
]
105+
isInside(rgbData, newLocation)
106+
if (isInside(rgbData, newLocation)) {
107+
queue.push(newLocation)
105108
}
106109
}
107110
}

0 commit comments

Comments
 (0)