349. Intersection of Two Arrays [LeetCode]

来源:互联网 发布:数据库pdforacle网盘 编辑:程序博客网 时间:2024/05/01 15:46

Given two arrays, write a function to compute their intersection.

Example:
Given nums1 = [1, 2, 2, 1]nums2 = [2, 2], return [2].

Note:

  • Each element in the result must be unique.
  • The result can be in any order.

根据题意,要求两个集合的交集。

思路:因为java中的set集合不包含重复元素,可以利用set集合来完成。

具体实现的java代码如下:


0 0
原创粉丝点击