@@ -120,6 +120,41 @@ func dfs(image [][]int, i, j, oc, nc int) {
120
120
}
121
121
```
122
122
123
+ ### ** Rust**
124
+
125
+ ``` rust
126
+ impl Solution {
127
+ fn dfs (i : usize , j : usize , target : i32 , new_color : i32 , image : & mut Vec <Vec <i32 >>) {
128
+ if image [i ][j ] != target {
129
+ return ;
130
+ }
131
+ image [i ][j ] = new_color ;
132
+ if i != 0 {
133
+ Self :: dfs (i - 1 , j , target , new_color , image );
134
+ }
135
+ if j != 0 {
136
+ Self :: dfs (i , j - 1 , target , new_color , image );
137
+ }
138
+ if i + 1 != image . len () {
139
+ Self :: dfs (i + 1 , j , target , new_color , image );
140
+ }
141
+ if j + 1 != image [0 ]. len () {
142
+ Self :: dfs (i , j + 1 , target , new_color , image );
143
+ }
144
+ }
145
+
146
+ pub fn flood_fill (mut image : Vec <Vec <i32 >>, sr : i32 , sc : i32 , new_color : i32 ) -> Vec <Vec <i32 >> {
147
+ let (sr , sc ) = (sr as usize , sc as usize );
148
+ let target = image [sr ][sc ];
149
+ if target == new_color {
150
+ return image ;
151
+ }
152
+ Self :: dfs (sr , sc , target , new_color , & mut image );
153
+ image
154
+ }
155
+ }
156
+ ```
157
+
123
158
### ** ...**
124
159
125
160
```
0 commit comments