Method
backtrace
(n: i32, k: usize, start_index: i32, path: &mut Vec<i32>, ret: &mut Vec<Vec<i32>>)
Source from the content-addressed store, hash-verified
| 3 | // 回溯 = 递归 + 循环 |
| 4 | impl Solution { |
| 5 | pub fn backtrace(n: i32, k: usize, start_index: i32, path: &mut Vec<i32>, ret: &mut Vec<Vec<i32>>) { |
| 6 | if path.len() == k { |
| 7 | ret.push(path.to_vec()); |
| 8 | return; |
| 9 | } |
| 10 | for i in start_index..=n { |
| 11 | path.push(i); |
| 12 | Self::backtrace(n, k, i+1, path, ret); |
| 13 | path.pop(); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | pub fn combine(n: i32, k: i32) -> Vec<Vec<i32>> { |
| 18 | let mut path = vec![]; |
Callers
nothing calls this directly
Tested by
no test coverage detected