什么是从列表中删除重复值的最佳算法?
我尝试了以下代码:
这里,
for (int i = 0; i < AuthorCounter-1; i++)
{
for (int j = 0; j < AuthorCounter-1; j++)
{
if (i != j)
{
if (AuthorGroupNode.Nodes[i].Text == AuthorGroupNode.Nodes[j].Text)
{
AuthorGroupNode.Nodes[j].Remove();
AuthorCounter--;
}
}
}
}
这里,
AuthorGroupNodes
是一个节点列表。它在某种程度上做得不错,但并不完美。有没有更好的解决方案?
list.Distinct().toList()
,但这可能不是最快的方法。 - Ray Toal