952. Largest Component Size by Common Factor Hard
1/**
2 * [952] Largest Component Size by Common Factor
3 *
4 * You are given an integer array of unique positive integers nums. Consider the following graph:
5 *
6 * There are nums.length nodes, labeled nums[0] to nums[nums.length - 1],
7 * There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share a common factor greater than 1.
8 *
9 * Return the size of the largest connected component in the graph.
10 *
11 * Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/01/ex1.png" style="width: 500px; height: 97px;" />
13 * Input: nums = [4,6,15,35]
14 * Output: 4
15 *
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/01/ex2.png" style="width: 500px; height: 85px;" />
18 * Input: nums = [20,50,9,63]
19 * Output: 2
20 *
21 * Example 3:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2018/12/01/ex3.png" style="width: 500px; height: 260px;" />
23 * Input: nums = [2,3,6,7,4,12,21,39]
24 * Output: 8
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= nums.length <= 2 * 10^4
30 * 1 <= nums[i] <= 10^5
31 * All the values of nums are unique.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/largest-component-size-by-common-factor/
37// discuss: https://leetcode.com/problems/largest-component-size-by-common-factor/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn largest_component_size(nums: Vec<i32>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_952() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.