Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
no he didn't :DDD
To enhance fastness, it would be better to convert the String to StringBuilder, do the replaces like we did with String, and then convert the SB back to String. But it would still remain in O(n), thus it may not be worth the effort, but is nice to know.
Both solutions are in the same complexity class O(n). So it's not really a win to use a for loop, instead of just replacing several times. Your code has also a bad readability, and is therefore less maintainable in production.
Our method will not be slow like you say, only somewhat slower than yours --> See big O notation: https://en.wikipedia.org/wiki/Big_O_notation
Yes, your solution is shorter. But I think that we (developers) should write faster code. Imagine that your method will execute 1_000_000 times in production every 1 minute. It will be slow.
Also I think that this kata we can't solve with regex, because we have several replace templates.
Sorry for bad English.
Correct, but its more concise than what you did with a boilerplate for loop. One line versus 11 lines on your code. Best way would of been to use regex and call .replace() once.
This will create 5 new String instances. Also this solution will make 5 loops for replace all characters.
This comment is hidden because it contains spoiler information about the solution