Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b137d79

Browse files
committed
feat:修改了剑指Offer 05题中的Java第一种解法
这里的charAt()函数返回的本身就是一个char型变量,因此我认为没必要将其转换成String类型,而是直接比较即可。
1 parent d89b396 commit b137d79

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

problems/剑指Offer05.替换空格.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public static String replaceSpace(StringBuffer str) {
134134
//使用 sb 逐个复制 str ,碰到空格则替换,否则直接复制
135135
for (int i = 0; i < str.length(); i++) {
136136
//str.charAt(i) 为 char 类型,为了比较需要将其转为和 " " 相同的字符串类型
137-
if (" ".equals(String.valueOf(str.charAt(i)))){
137+
//if (" ".equals(String.valueOf(str.charAt(i)))){
138+
if (s.charAt(i) == ' ') {
138139
sb.append("%20");
139140
} else {
140141
sb.append(str.charAt(i));

0 commit comments

Comments
 (0)