C++ || Easy Approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(n*n)+O(nlogn)+O(n)\n\n- Space complexity:O(n)\n\n# Code\n\nclass Solution {\npublic:\
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(n*n)+O(nlogn)+O(n)\n\n- Space complexity:O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> largestDivisibleSubset(vector<int>& nums) {\n        int n=nums.size(), maxi=1, num=-1;\n        vector<int>v;\n        sort(nums.begin(), nums.end());\n        vector<int>dp(n, 1);\n        for(int i=1; i<n; i++){\n            for(int j=0; j<i; j++){\n                if(!(nums[i]%nums[j]) && dp[i]<dp[j]+1){\n                    dp[i]=dp[j]+1;\n                    if(maxi<dp[i]){\n                        maxi=dp[i];\n                    }\n                }\n            }\n        }\n        for(int i=n-1; i>=0; i--){\n            if(maxi==dp[i] && (num==-1 || !(num%nums[i]))){\n                v.push_back(nums[i]);\n                maxi--;\n                num=nums[i];\n            }\n        }\n        return v;\n    }\n};\n```
['Array', 'Math', 'Sorting', 'C++']