c# leetcode 884

很经典

【1,1】

【2,2

【3,1】

string[] chA = A.Split(' ');
            string[] chB = B.Split(' ');
            List<string> res = new List<string>();
            var dic = new Dictionary<string, int>();
            for (int i = 0; i < chA.Length; i++)
            {
                if (dic.ContainsKey(chA[i]))
                {
                    dic[chA[i]]++;
                }
                else
                {
                    dic[chA[i]]=1;
                }
            }
            for (int i = 0; i < chB.Length; i++)
            {
                if (dic.ContainsKey(chB[i]))
                {
                    dic[chB[i]]++;
                }
                else
                {
                    dic[chB[i]] = 1;
                }
            } 
            foreach (var item in dic)
            {
                if (item.Value==1)
                {
                    res.Add(item.Key);
                }
            }
            return res.ToArray();

猜你喜欢

转载自blog.csdn.net/us2019/article/details/86486402
今日推荐