Skip to content

Commit 8f1cae3

Browse files
authored
Merge pull request Snailclimb#299 from chndgh/master
Fix wrong logic
2 parents 6db8a95 + f46d1a7 commit 8f1cae3

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

docs/dataStructures-algorithms/几道常见的子符串算法题.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class Main {
112112
public static String replaceSpace(String[] strs) {
113113

114114
// 如果检查值不合法及就返回空串
115-
if (!chechStrs(strs)) {
115+
if (!checkStrs(strs)) {
116116
return "";
117117
}
118118
// 数组长度
@@ -135,21 +135,17 @@ public class Main {
135135

136136
}
137137

138-
private static boolean chechStrs(String[] strs) {
139-
boolean flag = false;
140-
// 注意:=是赋值,==是判断
141-
if (strs != null) {
142-
// 遍历strs检查元素值
143-
for (int i = 0; i < strs.length; i++) {
144-
if (strs[i] != null && strs[i].length() != 0) {
145-
flag = true;
146-
} else {
147-
flag = false;
148-
}
149-
}
150-
}
151-
return flag;
152-
}
138+
private static boolean checkStrs(String[] strs) {
139+
if (strs != null) {
140+
// 遍历strs检查元素值
141+
for (int i = 0; i < strs.length; i++) {
142+
if (strs[i] == null || strs[i].length() == 0) {
143+
return false;
144+
}
145+
}
146+
}
147+
return true;
148+
}
153149

154150
// 测试
155151
public static void main(String[] args) {

0 commit comments

Comments
 (0)