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
return helper(start + 1, nums, sum1 + nums[start], sum2)
|| helper(start + 1, nums, sum1, sum2 + nums[start]);
returns true
if either call to helper()
returns true. Here is the same code written a different but functionally equivalent way:
boolean helperResponse1 = helper(start + 1, nums, sum1 + nums[start], sum2);
if (helperResponse1 == true)
return true;
else {
boolean helperResponse2 = helper(start + 1, nums, sum1, sum2 + nums[start]);
if (helperResponse2 == true)
return true;
else
return false;
}
I put in a lot of unnecessary stuff for the sake of clarity.