Exemplo n.º 1
0
        //804
        public int UniqueMorseRepresentations(string[] words)
        {
            string[] letters = new string[] { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
            BinarySearchTreeSet <string> binarySearchTreeSet = new BinarySearchTreeSet <string>();

            foreach (string word in words)
            {
                StringBuilder builder = new StringBuilder();
                foreach (char c in word)
                {
                    builder.Append(letters[c - 'a']);
                }
                binarySearchTreeSet.Add(builder.ToString());
            }

            return(binarySearchTreeSet.Size);
        }
Exemplo n.º 2
0
        //349
        public static int[] Intersection(int[] nums1, int[] nums2)
        {
            BinarySearchTreeSet <int> binarySearchTreeSet = new BinarySearchTreeSet <int>();

            foreach (var num in nums1)
            {
                binarySearchTreeSet.Add(num);
            }
            List <int> list = new List <int>();

            foreach (var num in nums2)
            {
                if (binarySearchTreeSet.Contains(num))
                {
                    list.Add(num);
                    binarySearchTreeSet.Remove(num);
                }
            }

            return(list.ToArray());
        }