怎么把多个有序的数组合并成一个数组,并且保证数组最短,同时保证合并后的数组还能保持各个数组的顺序?

例如:
数组1:[1,3,4]
数组2:[3,2,5]
数组3:[1,3,5]

合并后的最短数组 :[1,3,2,4,5] 或者 [1,3,4,2,5] 或者 [1,3,2,5,4],求出其中
一种情况就行。这个数组能够同时满足原来三个数组的元素排列顺序。
求大佬指点算法,什么语言都行

下面用python的set的union方法实现的(这里安装了boltons,如果直接用set,会自动排序),输出[1, 3, 4, 2, 5]

from boltons.setutils import IndexedSet

a=[1,3,4]
b=[3,2,5]
c=[1,3,5]

result = IndexedSet(a).union(IndexedSet(b)).union(IndexedSet(c))

print(result)

https://stackoverflow.com/questions/1653970/does-python-have-an-ordered-set

你研究下union方法

c#实现如下:

int[] a = { 1, 3, 4 };
int[] b = { 3, 2, 5 };
int[] c = { 1, 3, 5 };

var result = a.Union(b).Union(c);

foreach(var item in result)
{
    Console.WriteLine(item);
}            

其Union的源码地址:https://github.com/dotnet/runtime/blob/master/src/libraries/System.Linq/src/System/Linq/Union.cs

可以用dfs,分别从三个数组取数,只返回最短的序列

先把三个数组合并成一个数组,然后循环判断,重复的去除,没重复的存入临时数组