3
List<string> ls = new List<string>();
Feed<Contact> f = cr.GetContacts();
foreach (Contact e in f.Entries)
foreach (EMail el in e.Emails)
if (!(ls.Contains(el.Address.Substring(el.Address.LastIndexOf('@')+1))))
ls.Add(el.Address.Substring(el.Address.LastIndexOf('@')+1));
在上面的代码中,我试图获得不同的域名的电子邮件ID,但我得到他们所有什么问题与我的逻辑?谷歌联系人中的不同域名
测试数据:
INP:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
... 这样20,000项
我需要得到DISTINCT
域
但我的O/P是
gmail.com
yahoo.com
gmail.com
gmail.com
someOtherDomain.com
实际上它应该是:
gmail.com yahoo.com someOtherDomain.com
使用列表这是O(n^2),使用HashSet而不是O(n)。但是我在这段代码中看不到一个错误。 – CodesInChaos 2010-11-24 14:19:55
使用`string []`作为输入来测试您的代码,并且它正常工作(除了区分大小写)。 – CodesInChaos 2010-11-24 14:25:43