【发布时间】:2017-12-19 12:22:44
【问题描述】:
检查 list1 中的字符串值是否存在于 list2 中的最有效方法是什么?
伪代码示例
StringList List1 = {"a", "b", "c", "d"};
StringList List2 = {"d", "c", "b", "a"};
foreach (string a in List1)
{
foreach (string b in List2)
{
if(a==b)
{
WriteLine("match");
}
}
}
这种方法太慢了,不是最好的解决方案,我正在使用的平台是 BI#,它是 C# 的衍生产品。当前库中不存在 Array.Exists。
【问题讨论】:
-
先排序或制作查找表通常可以让您获得比二次算法更快的速度