Given an integer, and a range of integers (both positive and negative) as input.
We need to calculate the possible combinations of the integers from the range that add up to the given integer.
For example:
Integer: 5
Range: -1, 0, 1, 2, 3, 4
Result:
[1, 4], [2, 3], [-1, 2, 4], [0, 1, 4], [0, 2, 3], [-1, 0, 2, 4], [-1, 1, 2, 3], [-1, 0, 1, 2, 3]
以
p Sumify::run(5, (-1..4).to_a)
为例,原来的算法会漏下[-1,0,1,2,3]这一组,不知我的理解对不对?按我对题意的理解,在你的基础上修改了一下: