Created
August 6, 2018 07:42
-
-
Save cashlo/078c62521b9d68799194125f05f53281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def largestDivisibleSubset(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: List[int] | |
""" | |
if not nums: return [] | |
from_big_nums = sorted(nums) | |
dp = [] | |
for i,n in enumerate(from_big_nums): | |
# print dp | |
last_divisiable = [s for s in dp if n % s[-1] == 0] | |
if last_divisiable: | |
dp.append(max(last_divisiable, key=len) + [n]) | |
else: | |
dp.append([n]) | |
# print dp | |
return max(dp, key=len) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment