Skip to content

Commit 9a0c325

Browse files
committed
Update 几道常见的字符串算法题.md
1 parent 671450a commit 9a0c325

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/cs-basics/algorithms/几道常见的字符串算法题.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ public class Solution {
6161
* 第二种方法:利用API替换掉所用空格,一行代码解决问题
6262
*/
6363
public static String replaceSpace2(StringBuffer str) {
64-
64+
6565
return str.toString().replaceAll("\\s", "%20");
6666
}
6767
}
6868

6969
```
7070

71+
对于替换固定字符(比如空格)的情况,第二种方法其实可以使用 `replace` 方法替换,性能更好!
72+
73+
```java
74+
str.toString().replace(" ","%20");
75+
```
76+
7177
## 3. 最长公共前缀
7278

7379
> Leetcode: 编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。

0 commit comments

Comments
 (0)