package question;/*@author: Roderland@create: 2020年08月14日---10:55*/public class Question733 {public static void main(String[] args) {int[][] arr = new int[][]{{1, 1, 1}, {1, 1, 0}, {1, 0, 1}};System.out.println(new Question733().floodFill(arr, 1, 1, 2));}int oldColor = -1;public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {if (oldColor == -1) oldColor = image[sr][sc];if (oldColor == newColor) return image;if (image[sr][sc] == oldColor) {image[sr][sc] = newColor;if (sr + 1 < image.length) floodFill(image, sr + 1, sc, newColor);if (sr - 1 >= 0) floodFill(image, sr - 1, sc, newColor);if (sc + 1 < image[sr].length) floodFill(image, sr, sc + 1, newColor);if (sc - 1 >= 0) floodFill(image, sr, sc - 1, newColor);}return image;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。