JAVA, 20ms, beats 99.28%
Use binary search to locate the next multiple of nums[i].\n\n/*\n * Process nums increasingly.\n * lens[i] denotes the max length of the subset constructed so f
Use binary search to locate the next multiple of nums[i].\n```\n/*\n * Process nums increasingly.\n * lens[i] denotes the max length of the subset constructed so far containing nums[i].\n * If nums[j] (j > i) is multiple of nums[i], then lens[j] = max(lens[j], lens[i] + 1)\n */\npublic class Solution {\n    public List<Integer> largestDivisibleSubset(int[] nums) {\n        int n = nums.length, maxIdx = 0;\n        List<Integer> ans = new LinkedList<>();\n        if (n == 0) return ans;\n        Arrays.sort(nums);\n        int[] lens = new int[n], prevs = new int[n];\n        Arrays.fill(prevs, -1);\n        for (int i = 0; nums[i] <= nums[n-1]/2; ++i) {\n            for (int j = i + 1, f = 2; nums[i] <= nums[n-1]/f; f = (nums[j] + nums[i] - 1)/nums[i]) {\n                int idx = Arrays.binarySearch(nums, j, n, f*nums[i]);\n                if (idx > 0 && lens[idx] <= lens[i]) {\n                    prevs[idx] = i;\n                    lens[idx] = lens[i] + 1;\n                    if (lens[idx] > lens[maxIdx]) maxIdx = idx;\n                }\n                j = idx >= 0 ? idx + 1 : -(idx + 1);\n                if (j >= n) break;\n            }\n        }\n        for (int i = maxIdx; i >= 0; i = prevs[i]) ans.add(0, nums[i]);\n        return ans;\n    }\n}\n```
[]