Alert observers will doubtless have noticed the opportunities I left for refactoring in my sugestion.campbell@campbellsComputer:~/java$ java DuplicateFinder zebra dog cat dog zebra zebra cat zebra horse cat zebra horse cat dog
4
There are three kinds of actuaries: those who can count, and those who can't.
Guillermo Ishi wrote:You have to compare every element to every other element and I don't think there's a way to do that that isn't quadratic. The nested loops just make it obvious what's happening.
There are three kinds of actuaries: those who can count, and those who can't.
Guillermo Ishi wrote:You have to compare every element to every other element and I don't think there's a way to do that that isn't quadratic. The nested loops just make it obvious what's happening.
Is there such a thing as O(nlogn + n)? Shouldn't it simply be O(nlogn)?Piet Souris wrote: . . . O(nlog(n) + n). . . .
Junilu Lacar wrote:
The deep nesting and arrow code anti-pattern actually make it more difficult to see what's happening in your solution.
There are three kinds of actuaries: those who can count, and those who can't.
Carey Brown wrote:
Guillermo Ishi wrote:You have to compare every element to every other element and I don't think there's a way to do that that isn't quadratic. The nested loops just make it obvious what's happening.
No, it's not. See my example which does not have nested loops.
Stephan van Hulst wrote:Here's another functional solution. I agree that it's not very readable, but it may be educational
Piet Souris wrote:@Junilu
I find your second method less readable than the first one. Also
the use of very long names does not increase the clarity.
Consider Paul's rocket mass heater. |