See More

package AlgoExpert_Medium; import java.util.List; import java.util.ArrayList; public class PowerSet { public static void main(String[] args) { List array = new ArrayList<>() ; array.add(1) ; array.add(2) ; array.add(3) ; System.out.println( powerset( array ) ) ; } public static List> powerset(List array) { List> list = new ArrayList>() ; list.add(new ArrayList<>() ) ; List current = new ArrayList<>() ; return pset(array, current, list) ; } public static List> pset ( List array, List current, List> list ) { for(int i=0 ; i current.get(current.size()-1) ) { // Nice use of || current.add(currentNumber) ; // Choose list.add(new ArrayList<>(current)) ; pset(array, current, list) ; // Explore current.remove(current.size()-1) ; // Unchoose } } } return list ; } }