提交 39c2bc7b authored 作者: 马晨俊's avatar 马晨俊

mcj:新增kmp非空判断

上级 8926542d
...@@ -39,7 +39,7 @@ public class KmpUtil { ...@@ -39,7 +39,7 @@ public class KmpUtil {
*/ */
public static int kmpMatch(String s, String t){ public static int kmpMatch(String s, String t){
char[] s_arr = s.toCharArray(); char[] s_arr = s.toCharArray();
if(t.isEmpty()){ if(t == null || t.isEmpty()){
return -1; return -1;
} }
char[] t_arr = t.toCharArray(); char[] t_arr = t.toCharArray();
...@@ -61,4 +61,9 @@ public class KmpUtil { ...@@ -61,4 +61,9 @@ public class KmpUtil {
return -1; return -1;
} }
} }
public static void main(String[] args) {
int fdf = KmpUtil.kmpMatch("fdf", "");
System.out.println(fdf);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论