That may be better for more expensive calculations, but the beauty of this design is that it mostly doesn't matter. That change could be entirely internal to the class, with no change to the external interface. So... we don't have to make any decision about it until we've tested the performance.
Maybe that was a joke only :)
This comment is hidden because it contains spoiler information about the solution
I do know regex :) What I didn't know was how to manage gsub with it and it is actually more difficult to read what is considered the top answer.
The
copy
allocates heap space (strdup) which I want to free to avoid leakage, and so doesarr
(malloc), butchar *p
is just a pointer.Not if the word chars are set to uniq before starting the count loop :)
Exactly..that is a good practice!
wow, ur a genius!
That may be better for more expensive calculations, but the beauty of this design is that it mostly doesn't matter. That change could be entirely internal to the class, with no change to the external interface. So... we don't have to make any decision about it until we've tested the performance.