Update 剑指 offer 题解.md

5. 替换空格   在for (int i = 0; i < str.length( ); i++)中,str还在一直append,for循环出不去,最终会报OOM
This commit is contained in:
YiliaZhang 2018-08-27 23:21:40 +08:00 committed by GitHub
parent 9e98742585
commit 785f48ba52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,7 +230,7 @@ Output:
```java
public String replaceSpace(StringBuffer str) {
int P1 = str.length() - 1;
for (int i = 0; i < str.length(); i++)
for (int i = 0; i < P1+1; i++)
if (str.charAt(i) == ' ')
str.append(" ");