Skip to content

Instantly share code, notes, and snippets.

@matthewrkula
Created November 12, 2014 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrkula/cd0881af1a5777167d2c to your computer and use it in GitHub Desktop.
Save matthewrkula/cd0881af1a5777167d2c to your computer and use it in GitHub Desktop.
public static void paintFill(int[][] image, int x, int y, int oldColor, int newColor) {
if (x < 0 || x == image[0].length || y < 0 || y == image.length) {
return;
}
if (image[y][x] == oldColor) {
image[y][x] = newColor;
paintFill(image, x + 1, y, oldColor, newColor);
paintFill(image, x - 1, y, oldColor, newColor);
paintFill(image, x, y + 1, oldColor, newColor);
paintFill(image, x, y - 1, oldColor, newColor);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment