Is there a better way to examine whether two string arrays have the same contents than this?
string[] first = new string[]{\"cat\",\"and\",\"mouse\"};
string[] s
This is O(n^2)
. If the arrays have the same length, sort them, then compare elements in the same position. This is O(n log n)
.
Or you can use a hash set or dictionary: insert each word in the first array, then see if every word in the second array is in the set or dictionary. This is O(n)
on average.