package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/largest-divisible-subset/
 */
public class Problem368 {
    public List<Integer> largestDivisibleSubset(int[] nums) {
        List<Integer> result = new ArrayList<>();
        // TODO
        return result;
    }

    public static void main(String[] args) {
        Problem368 prob = new Problem368();
        System.out.println(prob.largestDivisibleSubset(new int[]{1, 2, 3})); // [1, 2]
        System.out.println(prob.largestDivisibleSubset(new int[]{1, 2, 4, 8})); // [1 ,2, 4, 8]
    }
}

@@ -40,16 +40,41 @@
 ayList;%0A
+import java.util.Arrays;%0A
 import j
@@ -306,15 +306,658 @@
     
-// TODO
+Arrays.sort(nums);%0A        for (int i = nums.length - 1; i %3E= 0; i--) %7B%0A            List%3CInteger%3E tmp = new ArrayList%3C%3E();%0A            for (int j = 0; j %3C i; j++) %7B%0A                if (nums%5Bi%5D %25 nums%5Bj%5D == 0) %7B%0A                    if (tmp.size() == 0) %7B%0A                        tmp.add(nums%5Bj%5D);%0A                    %7D else %7B%0A                        if (nums%5Bj%5D %25 tmp.get(tmp.size() - 1) == 0) %7B%0A                            tmp.add(nums%5Bj%5D);%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A            tmp.add(nums%5Bi%5D);%0A            if (result.size() %3C tmp.size()) %7B%0A                result = tmp;%0A            %7D%0A        %7D
 %0A   
@@ -1068,24 +1068,111 @@
 oblem368();%0A
+        System.out.println(prob.largestDivisibleSubset(new int%5B%5D%7B546, 669%7D)); // %5B546%5D%0A
         Syst
@@ -1321,31 +1321,335 @@
  2, 
-4, 8%7D)); // %5B1 ,2, 4, 8
+3, 6%7D)); // %5B1, 2, 6%5D%0A        System.out.println(prob.largestDivisibleSubset(new int%5B%5D%7B1, 2, 4, 8%7D)); // %5B1, 2, 4, 8%5D%0A        System.out.println(prob.largestDivisibleSubset(new int%5B%5D%7B1, 2, 4, 8, 9, 72%7D)); // %5B1, 2, 4, 8, 72%5D%0A        System.out.println(prob.largestDivisibleSubset(new int%5B%5D%7B1, 2, 3, 4, 6, 24%7D)); // %5B1, 2, 4, 24
 %5D%0A  

Update problem 368