Esempio n. 1
0
        public static int[] Intersect(int[] nums1, int[] nums2)
        {
            BinarySearchTreeDictionary <int, int> dictionary = new BinarySearchTreeDictionary <int, int>();

            foreach (var num in nums1)
            {
                if (!dictionary.Contains(num))
                {
                    dictionary.Add(num, 1);
                }
                else
                {
                    dictionary.Set(num, dictionary.Get(num) + 1);
                }
            }
            List <int> list = new List <int>();

            foreach (var num in nums2)
            {
                if (dictionary.Contains(num))
                {
                    list.Add(num);
                    dictionary.Set(num, dictionary.Get(num) - 1);
                    if (dictionary.Get(num) == 0)
                    {
                        dictionary.Remove(num);
                    }
                }
            }

            return(list.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        public static void TestDictionary()
        {
            LinkedListDictionary <string, int> dic = new LinkedListDictionary <string, int>();

            dic.Add("ss", 12);
            dic.Add("rng", 58);
            dic.Remove("ss");

            BinarySearchTreeDictionary <string, int> dictionary = new BinarySearchTreeDictionary <string, int>();

            dictionary.Add("edg", 156);
            dictionary.Add("vg", 456);
            dictionary.Set("vg", 789);
            dictionary.Remove("edg");
        }