-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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( |
There was a problem hiding this comment.
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>> { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return; | ||
} | ||
|
||
// Explore all combinations starting from 'start_index' |
There was a problem hiding this comment.
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
My first pull request ever so be forgiving.