Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions docs/dataStructures-algorithms/几道常见的子符串算法题.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class Main {
public static String replaceSpace(String[] strs) {

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

}

private static boolean chechStrs(String[] strs) {
boolean flag = false;
// 注意:=是赋值,==是判断
if (strs != null) {
// 遍历strs检查元素值
for (int i = 0; i < strs.length; i++) {
if (strs[i] != null && strs[i].length() != 0) {
flag = true;
} else {
flag = false;
}
}
}
return flag;
}
private static boolean checkStrs(String[] strs) {
if (strs != null) {
// 遍历strs检查元素值
for (int i = 0; i < strs.length; i++) {
if (strs[i] == null || strs[i].length() == 0) {
return false;
}
}
}
return true;
}

// 测试
public static void main(String[] args) {
Expand Down