Class Solution
-
- All Implemented Interfaces:
public final class Solution952 - Largest Component Size by Common Factor\.
Hard
You are given an integer array of unique positive integers
nums. Consider the following graph:There are
nums.lengthnodes, labelednums[0]tonums[nums.length - 1],There is an undirected edge between
nums[i]andnums[j]ifnums[i]andnums[j]share a common factor greater than1.
Return the size of the largest connected component in the graph.
Example 1:
Input: nums = 4,6,15,35
Output: 4
Example 2:
Input: nums = 20,50,9,63
Output: 2
Example 3:
Input: nums = 2,3,6,7,4,12,21,39
Output: 8
Constraints:
<code>1 <= nums.length <= 2 * 10<sup>4</sup></code>
<code>1 <= numsi<= 10<sup>5</sup></code>
All the values of
numsare unique.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerlargestComponentSize(IntArray nums)-
-
Method Detail
-
largestComponentSize
final Integer largestComponentSize(IntArray nums)
-
-
-
-