LeetCode Solutions/Algorithm I/Day 7 Breadth-First Search - Depth-First Search/Flood Fill.java
class Solution {
    public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
        if(image==null || image.length==0) return null;
        
        int color=image[sr][sc];
        if(color!=newColor) dfs(image,sr,sc,color, newColor);
        return image;    
    }
    
    public void dfs(int[][] image, int sr, int sc, int color, int newColor){
        if(sr<0 || sr>=image.length || sc<0 || sc>=image[0].length || image[sr][sc]!=color) return;
        
        image[sr][sc]=newColor;
        
        dfs(image,sr+1,sc,color,newColor);
        dfs(image,sr,sc+1,color,newColor);
        dfs(image,sr-1,sc,color,newColor);
        dfs(image,sr,sc-1,color,newColor);
    }
}