update at 2022-03-12 23:18:23 by ehlxr

master
ehlxr 2022-03-12 23:18:23 +08:00
parent 6cfb4fd37e
commit 4cd72cd4f2
1 changed files with 2 additions and 6 deletions

View File

@ -35,17 +35,13 @@ public class BruteForce {
String s = "abdcfhjudfadf";
String p = "dcf";
System.out.println(match(s, p));
System.out.println(bf(s, p));
}
public static int match(String s, String p) {
public static int bf(String s, String p) {
int sl = s.length();
int pl = p.length();
if (sl <= pl && !s.equals(p)) {
return -1;
}
for (int i = 0; i <= sl - pl; i++) {
int j = 0;
for (; j < pl; j++) {