C# Solutions


  • 0
    T
     public int[] Intersection(int[] nums1, int[] nums2) {
            Dictionary <int,int> result= new Dictionary<int,int>();
            Array.Sort(nums1);
            Array.Sort(nums2);
            for(int i=0,j=0; i<nums1.Length && j<nums2.Length;)
            {
                if(nums1[i]==nums2[j] && !result.ContainsKey(nums1[i]))
                {
                    result.Add(nums1[i],nums1[i]);
                }
                if(nums1[i]<nums2[j])
                {
                    i++;
                }else
                {
                    j++;
                }
                
            }
            return result.Values.ToArray();
            
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.