Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 538591b

Browse files
Merge pull request youngyangyang04#2243 from fwqaaq/master-4
Update 0797.所有可能的路径.md about rust
2 parents 9f23129 + 264b72f commit 538591b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎problems/0797.所有可能的路径.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,29 @@ class Solution:
217217
self.path.pop() # 回溯
218218
```
219219

220+
### Rust
221+
222+
```rust
223+
impl Solution {
224+
pub fn all_paths_source_target(graph: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
225+
let (mut res, mut path) = (vec![], vec![0]);
226+
Self::dfs(&graph, &mut path, &mut res, 0);
227+
res
228+
}
220229

230+
pub fn dfs(graph: &Vec<Vec<i32>>, path: &mut Vec<i32>, res: &mut Vec<Vec<i32>>, node: usize) {
231+
if node == graph.len() - 1 {
232+
res.push(path.clone());
233+
return;
234+
}
235+
for &v in &graph[node] {
236+
path.push(v);
237+
Self::dfs(graph, path, res, v as usize);
238+
path.pop();
239+
}
240+
}
241+
}
242+
```
221243

222244
<p align="center">
223245
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /