Given a bunch of integer numbers, please output all combination of all possible numbers by using plus operation only

Given a bunch of integer numbers, please output all combination of all possible numbers by using plus operation only.

For example,

[10, 20] => [10, 20, 30]

[1, 2, 3] => [1, 2, 3, 4, 5, 6]

[10, 20, 20, 50] => [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

Could someone help me with a method to do that in Java ?

I have made tries and I think it works, but looking for other solutions.

public int[] getCoins2(int[] coins) {

Set result = new TreeSet<>();

for (int coin : coins) {

result.addAll(result.stream().map(value -> value +...

Read More »

By: StackOverFlow - Tuesday, 20 November

Related Posts