调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你一个二维整数数组 properties,其维度为 n x m,以及一个整数 k

定义一个函数 intersect(a, b),它返回数组 ab 共有的不同整数的数量

构造一个 无向图,其中每个索引 i 对应 properties[i]。如果且仅当 intersect(properties[i], properties[j]) >= k(其中 ij 的范围为 [0, n - 1]i != j),节点 i 和节点 j 之间有一条边。

返回结果图中 连通分量 的数量。

 

示例 1:

输入: properties = [[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]], k = 1

输出: 3

解释:

生成的图有 3 个连通分量:

示例 2:

输入: properties = [[1,2,3],[2,3,4],[4,3,5]], k = 2

输出: 1

解释:

生成的图有 1 个连通分量:

示例 3:

输入: properties = [[1,1],[1,1]], k = 2

输出: 2

解释:

intersect(properties[0], properties[1]) = 1,小于 k。因此在图中 properties[0]properties[1] 之间没有边。

 

提示:

  • 1 <= n == properties.length <= 100
  • 1 <= m == properties[i].length <= 100
  • 1 <= properties[i][j] <= 100
  • 1 <= k <= m
通过次数
3.2K
提交次数
6.5K
通过率
48.3%


相关企业

提示 1
How can we optimally find the intersection of two arrays? One way is to use len(set(a) & set(b)).

提示 2
For connected components, think about using DFS, BFS, or DSU.

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
properties =
[[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]]
k =
1
Source