Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    368 - Largest Divisible Subset\.

    Medium

    Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:

    • answer[i] % answer[j] == 0, or

    • answer[j] % answer[i] == 0

    If there are multiple solutions, return any of them.

    Example 1:

    Input: nums = 1,2,3

    Output: 1,2

    Explanation: 1,3 is also accepted.

    Example 2:

    Input: nums = 1,2,4,8

    Output: 1,2,4,8

    Constraints:

    • 1 <= nums.length <= 1000

    • <code>1 <= numsi<= 2 * 10<sup>9</sup></code>

    • All the integers in nums are unique.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final List<Integer> largestDivisibleSubset(IntArray nums)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait