You are given K sorted integer arrays (non-decreasing). Arrays may contain duplicates within the same array and across different arrays.
Return a sorted list of unique integers that appear in any of the arrays (i.e., the set union, sorted).
Example:
A = [-100, -1, -1, 0, 5]
B = [0]
C = [-1, 0, 0]
Output → [-100, -1, 0, 5]
Constraints (typical):
- Total length
Nacross all arrays can be large. - Values fit in 32-bit signed int.
K ≥ 1.
用 最小堆的 K 路归并 :堆里放 (值, 数组编号, 索引),每次弹出最小值,若与 上一次输出相同则跳过 ,否则写入结果;随后把该数组的下一个元素压回堆。时间 O(N log K),空间 O(K)。
如果 K 很小(如 2 或 3),也可用 多指针线性扫描,逐次取最小并跳过相等元素,整体 O(N)。
VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 OpenAI、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Stripe 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。