[Java]-Simple Dynammic Programming beats 57.40% Java online Submission
Runtime: 18 ms, faster than 57.40% of Java online submissions for Largest Divisible Subset.\n# Memory Usage: 38.9 MB, less than 9.09% of Java online submissions
# Runtime: 18 ms, faster than 57.40% of Java online submissions for Largest Divisible Subset.\n# Memory Usage: 38.9 MB, less than 9.09% of Java online submissions for Largest Divisible Subset.\n\n```\nclass Solution {\n    public List<Integer> largestDivisibleSubset(int[] nums) {\n        if(nums.length==0) return new ArrayList<>();\n        int n = nums.length;\n        Arrays.sort(nums);\n        int[] dp = new int[n];\n        Arrays.fill(dp,1);\n        int index =0,max=1;\n        for(int i = 1;i<n;i++){\n            for(int j=0;j<i;j++){\n                dp[i] = nums[i]%nums[j]==0?Math.max(dp[i],dp[j]+1):dp[i];\n                if(dp[i]>max){\n                    index = i;\n                    max = dp[i];\n                }\n            }\n        }\n        List<Integer> a = new ArrayList<>();\n        int last = nums[index];a.add(last);max--;\n        for(int i=index-1;i>=0;i--){\n            if(last%nums[i]==0&&dp[i]==max){\n                a.add(nums[i]);\n                max--;\n            }\n        }\n        return a;\n    }\n}\n```
['Dynamic Programming', 'Java']