Skip to content

Add Rust Backtracking #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add Rust Backtracking #89

wants to merge 1 commit into from

Conversation

40tude
Copy link

@40tude 40tude commented Jun 24, 2025

My first pull request ever so be forgiving.

Copy link
Collaborator

@Destiny-02 Destiny-02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @40tude! Thanks for making your first PR to the solutions repository! I have reviewed the first file and left some comments. In general, the rust solutions need to match the python solutions as close as possible. I like to compare each file and line side by side. ChatGPT also helps 😁.

@@ -0,0 +1,40 @@
fn dfs(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combination_of_sum.rs -> combinations_of_sum_k.rs

}
}

fn combinations_of_sum_k(nums: &[u32], target: u32) -> Vec<Vec<u32>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please order this function first, before the dfs function


fn combinations_of_sum_k(nums: &[u32], target: u32) -> Vec<Vec<u32>> {
let mut sorted_nums = nums.to_vec();
sorted_nums.sort_unstable(); // Sort the numbers to allow early stopping
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the sorting. We'd like to keep it consistent with the python solutions, which don't do any sorting here.

if target == 0 {
res.push(combination.clone());
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the rust equivalent below
image

return;
}

// Explore all combinations starting from 'start_index'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to keep the comments and the logic structure the same as Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants