We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Similar logic, except using indexOf(str, int) function.
boolean found = false;
int k = -1;
int l = -1;
outerLoop:
for(int i=0; i < R; ) {
l = k;
k = G[i].indexOf(P[0], l+1);
//System.out.println("lk is " + l+k);
if ( k != -1) {
for(int j = 1; j < r; j++) {
String local = G[i+j].substring(k, k+c);
//System.out.println("local for j = " + j + " is " + local);
if (!local.equals(P[j])) {
found = false;
continue outerLoop;
} else {
//System.out.println("found match in iteration " + i + j);
found = true;
if (j == r-1)
break outerLoop;
continue;
}
}
}
i++;
}
System.out.println(found ? "YES" : "NO");
The Grid Search
You are viewing a single comment's thread. Return to all comments →
Similar logic, except using indexOf(str, int) function.