Applying this to the problem at hand, doSomeOperation()
for us would mean checking the currently investigated node position at both the first and second trees, and deciding what to return.
But what do we need to get back? Here's an operation that might work given our examples:
xxxxxxxxxx
if (tree1 == null) {
return tree2;
}
if (tree2 == null) {
return tree1;
}
tree1.val = tree1.val + tree2.val
return tree1;
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment