[CC150] Ch1.5 Replace spaces
1.5 Write a method to replace all spaces in a string with ‘%20’.
It is inefficient to direct replace all spaces since each replace will move all following characters. The worst case complexity is O(n^2).
If we use a new string and dynamically increase the size, the complexity is O(n).
If only C-style string is allowed, the solution needs to be modified but is still simple.
It is inefficient to direct replace all spaces since each replace will move all following characters. The worst case complexity is O(n^2).
If we use a new string and dynamically increase the size, the complexity is O(n).
If only C-style string is allowed, the solution needs to be modified but is still simple.
Comments
Post a Comment