4 ms·
I took a quick crack at this [1] and I have a few comments: 1. The double-linking and circularity make the solution uglier and more fiddly without making it re
by icambron 5y ago
I took a quick crack at this [1] and I have a few comments:
1. The double-linking and circularity make the solution uglier and more fiddly without making it really conceptually any harder. In particular, it means you end up mixing recursion with mutation, which is a little gunky. I wish they'd just have you output a single-linked list: same bang, less buck.
2. The problem mentions that the double-linked list nodes look a lot like the tree nodes, in the sense that they're a value with two pointers, but in practice that didn't have any effect on the solution, and I'm not really sure it's very interesting.
3. A thing that always comes up in these kinds of recursion problems is where to put the null checks, which in this case are a little complicated. I think neither my solution and the Java one in the link do a great job on that front
[1] https://gist.github.com/icambron/4c03e1b19c3ca795d3930ed1720684af https://gist.github.com/icambron/4c03e1b19c3ca795d3930ed1720...