diff --git a/codes/rust/chapter_backtracking/permutations_i.rs b/codes/rust/chapter_backtracking/permutations_i.rs index dae411014..3e2eec41f 100644 --- a/codes/rust/chapter_backtracking/permutations_i.rs +++ b/codes/rust/chapter_backtracking/permutations_i.rs @@ -23,7 +23,7 @@ fn backtrack(mut state: Vec, choices: &[i32], selected: &mut [bool], res: & backtrack(state.clone(), choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; - state.remove(state.len() - 1); + state.pop(); } } } diff --git a/codes/rust/chapter_backtracking/permutations_ii.rs b/codes/rust/chapter_backtracking/permutations_ii.rs index 9c422b6e0..d2db56928 100644 --- a/codes/rust/chapter_backtracking/permutations_ii.rs +++ b/codes/rust/chapter_backtracking/permutations_ii.rs @@ -27,7 +27,7 @@ fn backtrack(mut state: Vec, choices: &[i32], selected: &mut [bool], res: & backtrack(state.clone(), choices, selected, res); // 回退:撤销选择,恢复到之前的状态 selected[i] = false; - state.remove(state.len() - 1); + state.pop(); } } }