I\'m new to programming so I have been working through the exercises at CodingBat.com. In the Recursion-2 section, there is a problem I wasn\'t able to solve (recursively) so I
That's not what it means. It doesn't mean "return either value, one or the other".
The return
statement returns the result of the entire expression. That is, the OR (||
) is evaluated first, before the return
, then the result of that expression is return
ed.
It might be more clearly written:
return (helper(start + 1, nums, sum1 + nums[start], sum2)
|| helper(start + 1, nums, sum1, sum2 + nums[start]) );