2 ms·
The problem with deduplicating the data can be changed into another problem: ensuring we won't add the data if it would be duplicated. So instead of trying to
by self_awareness 8y ago
The problem with deduplicating the data can be changed into another problem: ensuring we won't add the data if it would be duplicated.
So instead of trying to deduplicate the array from author's example, I'd change the 'add()' method so that it searches through the whole set and doesn't add the data if it's already added.
So now it doesn't require deduplication code at all.
- bryanrasmussen 8y agoI can't help but think that deduplicating once after you've got your array ready to process is better than checking each time when you add if the value is already there.
- Adamantcheese 8y agoThat's what I though as well. In which case it's better to just keep it in a set-like structure initially, or just dump your entire array into a set afterwards. That's linear time, which is loads better than any of the solutions presented.