[LeetCode]Intersection of Two Arrays

[LeetCode]Intersection of Two Arrays

很简单的一道题
扫一遍就好

    public class Solution
    {
        public int[] Intersection(int[] nums1, int[] nums2)
        {
            if (nums1.Length == 0 || nums2.Length == 0)
            {
                int[] emptyArray = new int[0];
                return emptyArray;
            }
            List<int> listNum = new List<int>();
            foreach (var i in nums2)
            {
                if (nums1.Contains(i) && !listNum.Contains(i))
                {
                    listNum.Add(i);
                }
            }
            return listNum.ToArray();
        }
    }

发表评论

电子邮件地址不会被公开。 必填项已用*标注