From 47776dbf467264c1d8b066cd6c74afe15bb0a5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=80=90=E5=BC=A0=E9=91=AB=E3=80=91?= <974567732@qq.com> Date: Thu, 25 Jul 2019 10:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E9=95=BF=E5=85=AC=E5=85=B1=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E9=A2=98=E7=9B=AE=E6=95=B0=E7=BB=84=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原文中的校验,存在边界问题,当 String[] strs = {};或者 String[] strs = null;时仍然会报错。 --- ...62\347\256\227\346\263\225\351\242\230.md" | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 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 cd2a3e31..aa06e900 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" @@ -135,17 +135,20 @@ public class Main { } - 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; - } + 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; + } // 测试 public static void main(String[] args) { -- GitLab