记rust的引用例子

拟墨画扇 提交于 2020-02-26 15:43:16
 1 impl Solution {
 2     pub fn flood_fill(image: Vec<Vec<i32>>, sr: i32, sc: i32, new_color: i32) -> Vec<Vec<i32>> {
 3         let mut image = image;
 4         let origin_Color = image[sr as usize][sc as usize].clone();
 5         Self::dfs(&mut image, sr, sc, origin_Color, new_color);
 6         image
 7     }
 8     fn dfs(image: &mut Vec<Vec<i32>>, sr:i32, sc:i32, origin_Color:i32, new_color:i32) {
 9         if sr < 0 || sc < 0 || sr >= image.len() as i32 || sc >= image[0].len() as i32 || image[sr as usize][sc as usize] == new_color || image[sr as usize][sc as usize] != origin_Color {
10             return;
11         }
12         image[sr as usize][sc as usize] = new_color;
13         Self::dfs(image, sr-1, sc, origin_Color, new_color);
14         Self::dfs(image, sr+1, sc, origin_Color, new_color);
15         Self::dfs(image, sr, sc-1, origin_Color, new_color);
16         Self::dfs(image, sr, sc+1, origin_Color, new_color);
17     }
18 }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!