码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Largest Divisible Subset 最大可整除的子集合

时间:2016-06-28 23:29:21      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

 

Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.

If there are multiple solutions, return any subset is fine.

Example 1:

nums: [1,2,3]

Result: [1,2] (of course, [1,3] will also be ok)

Example 2:

nums: [1,2,4,8]

Result: [1,2,4,8]

Credits:
Special thanks to @Stomach_ache for adding this problem and creating all test cases.

 

[LeetCode] Largest Divisible Subset 最大可整除的子集合

标签:

原文地址:http://www.cnblogs.com/grandyang/p/5625209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!