十个不同长度数组同顺序对比取得与原所有数组都不重复的数字
时间: 2024-03-12 18:46:35 浏览: 46
对于这个问题,可以使用上面提到的方法,在合并所有数组后对数字进行去重,然后再对每个原始数组进行处理,只保留其中不在去重后的数组中出现的数字。代码示例如下:
```python
# 十个不同长度的数组
arrays = [
[1, 2, 3],
[2, 3, 4, 5],
[3, 4, 5, 6, 7],
[4, 5, 6, 7, 8, 9],
[5, 6, 7, 8, 9, 10, 11],
[6, 7, 8, 9, 10, 11, 12, 13],
[7, 8, 9, 10, 11, 12, 13, 14, 15],
[8, 9, 10, 11, 12, 13, 14, 15, 16, 17],
[9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
]
# 合并所有数组并排序
merged_array = sorted([num for array in arrays for num in array])
# 去重
new_merged_array = []
for i in range(1, len(merged_array)):
if merged_array[i] != merged_array[i-1]:
new_merged_array.append(merged_array[i-1])
new_merged_array.append(merged_array[-1])
# 对每个数组提取与去重后数组不重复的数字
for array in arrays:
unique_nums = []
for num in array:
if num not in new_merged_array or num in unique_nums:
continue
for i in range(1, len(new_merged_array)):
if num < new_merged_array[i]:
unique_nums.append(num)
break
else:
unique_nums.append(num)
print(unique_nums)
```
输出结果:
```
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
阅读全文