首页 > 其他 > 详细

记rust的引用例子

时间:2020-02-26 15:01:02      阅读:71      评论:0      收藏:0      [点我收藏+]
 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 }

 

记rust的引用例子

原文:https://www.cnblogs.com/chenguifeng/p/12366980.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!