diff --git a/codes/rust/chapter_backtracking/permutations_i.rs b/codes/rust/chapter_backtracking/permutations_i.rs index dae4110143..3e2eec41f3 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 9c422b6e0e..d2db569289 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(); } } }