update at 2022-03-12 23:18:23 by ehlxr
parent
6cfb4fd37e
commit
4cd72cd4f2
|
@ -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++) {
|
||||
|
|
Loading…
Reference in New Issue