LinkedList<Integer> list = newLinkedList<>(); for (inti=0; i < k; i++) { if (isMajor(n[i], treeSets, i)) { list.add(n[i]); } }
int[] array = newint[list.size()]; for (inti=0; i < array.length; i++) { array[i] = list.get(i); }
Arrays.sort(array);
for (inti= array.length - 1; i > 0; i--) { System.out.print(array[i] + " "); } System.out.print(array[0]); }
privatestaticbooleanisMajor(int n, TreeSet[] treeSets, int index) { for (inti=0; i < treeSets.length; i++) { if (i != index && treeSets[i].contains(n)) { returnfalse; } } returntrue; }
privatestatic TreeSet<Integer> getNumber(int n) { TreeSet<Integer> treeSet = newTreeSet<>(); treeSet.add(n); while (n != 1) { if (n % 2 == 0) { n = n / 2; } else {