fix: correct implementation of indexOf (#5)

LithoAdRemoval.indexOf never increments the index for the outer loop, causing an infinite loop
This commit is contained in:
Lachlan Wimsett 2022-04-09 05:25:38 +12:00 committed by GitHub
parent 14c5d21f9d
commit 4da053804b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -188,14 +188,17 @@ public class LithoAdRemoval {
return 0;
}
int i = 0;
while (i < array.length - target.length + 1 ){
for (int i = 0; i < array.length - target.length + 1; i++) {
boolean targetFound = true;
for (int j = 0; j < target.length; j++) {
if (array[i+j] != target[j]) {
targetFound = false;
break;
}
}
return i;
if (targetFound) {
return i;
}
}
return -1;
}