1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最大整除子集 [largest-divisible-subset].html
2022-03-29 12:43:11 +08:00

35 lines
1006 B
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

给你一个由 <strong>无重复</strong> 正整数组成的集合 <code>nums</code> ,请你找出并返回其中最大的整除子集 <code>answer</code> ,子集中每一元素对 <code>(answer[i], answer[j])</code> 都应当满足:
<ul>
<li><code>answer[i] % answer[j] == 0</code> ,或</li>
<li><code>answer[j] % answer[i] == 0</code></li>
</ul>
<p>如果存在多个有效解子集,返回其中任何一个均可。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3]
<strong>输出:</strong>[1,2]
<strong>解释:</strong>[1,3] 也会被视为正确答案。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,4,8]
<strong>输出:</strong>[1,2,4,8]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 1000</code></li>
<li><code>1 <= nums[i] <= 2 * 10<sup>9</sup></code></li>
<li><code>nums</code> 中的所有整数 <strong>互不相同</strong></li>
</ul>