我最近发现了一个类似的问题:
"Given an array of strings, return the number of distinct strings in that array."
我想出了这个解决方案:
1. Get number_of_strings, which equals the number of strings in the input array
2. Get number_of_non_redundant, which equals the length of the input array cast as a set
3. Return 2 times number_of_non_redundant - number_of_strings
所以,我的问题是,这个算法是否适用于所有数据集?