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

View File

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