Use a data structure that can much more efficiently determine if an item exists, namely a HashSet
. It can determine if an item is in the set in constant time, regardless of the number of items in the set.
If you really need the items in a List
instead, or you need the items in the resulting list to be in the order they were generated, then you can store the data in both a list and a hashset; adding the item to both collections if it doesn't currently exist in the HashSet
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…