368. Largest Divisible Subset Medium
1/**
2 * [368] Largest Divisible Subset
3 *
4 * 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:
5 *
6 * answer[i] % answer[j] == 0, or
7 * answer[j] % answer[i] == 0
8 *
9 * If there are multiple solutions, return any of them.
10 *
11 * Example 1:
12 *
13 * Input: nums = [1,2,3]
14 * Output: [1,2]
15 * Explanation: [1,3] is also accepted.
16 *
17 * Example 2:
18 *
19 * Input: nums = [1,2,4,8]
20 * Output: [1,2,4,8]
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= nums.length <= 1000
26 * 1 <= nums[i] <= 2 * 10^9
27 * All the integers in nums are unique.
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/largest-divisible-subset/
33// discuss: https://leetcode.com/problems/largest-divisible-subset/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn largest_divisible_subset(nums: Vec<i32>) -> Vec<i32> {
39 vec![]
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_368() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.