From f46d1a74b409a5968cbe086f8238de91f8ba7395 Mon Sep 17 00:00:00 2001 From: chndgh Date: Mon, 6 May 2019 22:16:35 +0800 Subject: [PATCH] original implementation cannot handle {"customer", "", "car"} --- ...62\347\256\227\346\263\225\351\242\230.md" | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git "a/docs/dataStructures-algorithms/\345\207\240\351\201\223\345\270\270\350\247\201\347\232\204\345\255\220\347\254\246\344\270\262\347\256\227\346\263\225\351\242\230.md" "b/docs/dataStructures-algorithms/\345\207\240\351\201\223\345\270\270\350\247\201\347\232\204\345\255\220\347\254\246\344\270\262\347\256\227\346\263\225\351\242\230.md" index 938f4a48..c85c1b74 100644 --- "a/docs/dataStructures-algorithms/\345\207\240\351\201\223\345\270\270\350\247\201\347\232\204\345\255\220\347\254\246\344\270\262\347\256\227\346\263\225\351\242\230.md" +++ "b/docs/dataStructures-algorithms/\345\207\240\351\201\223\345\270\270\350\247\201\347\232\204\345\255\220\347\254\246\344\270\262\347\256\227\346\263\225\351\242\230.md" @@ -112,7 +112,7 @@ public class Main { public static String replaceSpace(String[] strs) { // 如果检查值不合法及就返回空串 - if (!chechStrs(strs)) { + if (!checkStrs(strs)) { return ""; } // 数组长度 @@ -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) { -- GitLab