题解 | #替换空格#
替换空格
https://www.nowcoder.com/practice/0e26e5551f2b489b9f58bc83aa4b6c68
C++三行扬了:
class Solution { public: string replaceSpace(string s) { int space, end = s.size() - 1; for (; (space = s.rfind(' ', end)) != string::npos; end = space) s.replace(space, 1, "%20"); return s; } };