update at 2022-03-12 23:18:23 by ehlxr
This commit is contained in:
@@ -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++) {
|
||||
|
Reference in New Issue
Block a user