Algorithm to get all the combinations of size n from an array (Java)? [closed]
问题 Right now I'm trying to write a function that takes an array and an integer n, and gives a list of each size n combination (so a list of int arrays). I am able to write it using n nested loops, but this only works for a specific size of subset. I can't figure out how to generalize it to work for any size of combination. I think I need to use recursion? This is the code for all combinations of 3 elements, and I need an algorithm for any number of elements. import java.util.List; import java