数组是另一个数组的子集 [英] An array is subset of another array

查看:105
本文介绍了数组是另一个数组的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何有效地检查整数数组中的所有元素是否是java中另一个数组的所有元素的子集?例如[33 11 23]是[11 23 33 42]的子集。在此先感谢。

How can I efficiently check to see whether all the elements in an integer array are subset of all elements of another Array in java? For example [33 11 23] is subset of [11 23 33 42]. Thanks in advance.

推荐答案

从超集数组中创建一个 HashSet 。检查子集数组的每个元素是否都包含在 HashSet 中。这是一个非常快速的操作。

Make a HashSet out of the superset array. Check if each of the elements of the subset array are contained in the HashSet. This is a very fast operation.

这篇关于数组是另一个数组的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆