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 1/2] =?UTF-8?q?=E6=9C=80=E9=95=BF=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E9=A2=98=E7=9B=AE=E6=95=B0=E7=BB=84=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=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;时仍然会报错。 --- .../几道常见的子符串算法题.md | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/dataStructures-algorithms/几道常见的子符串算法题.md b/docs/dataStructures-algorithms/几道常见的子符串算法题.md index cd2a3e31..aa06e900 100644 --- a/docs/dataStructures-algorithms/几道常见的子符串算法题.md +++ b/docs/dataStructures-algorithms/几道常见的子符串算法题.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) { From 45e24a816ec5d9e6bf2e0f22515cc995409051bf 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 14:51:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9C=80=E9=95=BF=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E9=A2=98=E7=9B=AE=E6=95=B0=E7=BB=84=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=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;时仍然会报错。 --- .../几道常见的子符串算法题.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/dataStructures-algorithms/几道常见的子符串算法题.md b/docs/dataStructures-algorithms/几道常见的子符串算法题.md index aa06e900..8489082b 100644 --- a/docs/dataStructures-algorithms/几道常见的子符串算法题.md +++ b/docs/dataStructures-algorithms/几道常见的子符串算法题.md @@ -144,6 +144,7 @@ public class Main { flag = true; } else { flag = false; + break; } } }