Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- import java.util.stream.Collectors;
- public class ConatCombinations {
- public static void main (String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int[] aa = {1, 2, 3, 4};
- List<Integer> proba =
- Arrays.stream(aa)
- .boxed()
- .collect(Collectors.toList());
- proba.forEach(System.out::print);
- var res = concatComb(new HashSet<>(), proba, 0);
- res.forEach(System.out::print);
- }
- static HashSet<List<Integer>> concatComb(HashSet<List<Integer>> result,
- List<Integer> inp, int index) {
- if (index == inp.size()) {
- List<Integer> next = new LinkedList<>();
- next.addAll(inp);
- result.add(next);
- }
- for (int i = index; i < inp.size(); i++) {
- concatComb(result, inp, ++index);
- index--;
- int first = inp.get(i);
- int second = inp.get(i + 1);
- inp.set(i + 1, first * 10 + second);
- inp.remove(i);
- concatComb(result, inp, index);
- inp.set(i, second);
- inp.add(i, first);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement