-
Notifications
You must be signed in to change notification settings - Fork 16
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
Amy W #8
base: master
Are you sure you want to change the base?
Amy W #8
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.
Nice work, I like the Set solution, and this works and works well. You hit the learning goals here. If you're curious about my solution (more DFS), you can see it here.
dogz = Set.new() | ||
doggos = Set.new() |
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.
Nice use of a Set
.
dogz1.add(i) | ||
doggos.add(i) | ||
|
||
return bipartition_helper(i, dislikes, dogz1, doggos1) || bipartition_helper(i, dislikes, dogz, doggos) |
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.
Originally seeing this pair of recursive calls in this method set off alarm bells, but then I traced through and it doesn't actually make many more recursive calls, it's just a little different from my solution. It does however mean you have do the nested if-else blocks below.
I instead assigned the current "color" for the current node and assigned it's neighbors the alternating color, and then continue in a depth-first-search, and I repeat until the stack is empty. If they already have an incompatible color I return false. This results in a bit simpler code.
This does work however and work well.
No description provided.