We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 671450a commit 9a0c325Copy full SHA for 9a0c325
1 file changed
docs/cs-basics/algorithms/几道常见的字符串算法题.md
@@ -61,13 +61,19 @@ public class Solution {
61
* 第二种方法:利用API替换掉所用空格,一行代码解决问题
62
*/
63
public static String replaceSpace2(StringBuffer str) {
64
-
+
65
return str.toString().replaceAll("\\s", "%20");
66
}
67
68
69
```
70
71
+对于替换固定字符(比如空格)的情况,第二种方法其实可以使用 `replace` 方法替换,性能更好!
72
73
+```java
74
+str.toString().replace(" ","%20");
75
+```
76
77
## 3. 最长公共前缀
78
79
> Leetcode: 编写一个函数来查找字符串数组中的最长公共前缀。如果不存在公共前缀,返回空字符串 ""。
0 commit comments