Merge pull request #1365 from TheAlgorithms/revert-1362-z-function

Revert "z function added"
This commit is contained in:
Sombit Bose 2020-07-22 23:32:04 +05:30 committed by GitHub
commit d2870c841d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 36 deletions

View File

@ -211,6 +211,3 @@
* [ShellSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/ShellSort.java) * [ShellSort](https://github.com/TheAlgorithms/Java/blob/master/Sorts/ShellSort.java)
* [SortAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/Sorts/SortAlgorithm.java) * [SortAlgorithm](https://github.com/TheAlgorithms/Java/blob/master/Sorts/SortAlgorithm.java)
* [SortUtils](https://github.com/TheAlgorithms/Java/blob/master/Sorts/SortUtils.java) * [SortUtils](https://github.com/TheAlgorithms/Java/blob/master/Sorts/SortUtils.java)
## Strings
* [ZFunction](https://github.com/TheAlgorithms/Java/blob/master/Strings/ZFunction.java)

View File

@ -1,33 +0,0 @@
// Initialisation of strings algorithm Z function
// detailed review and proper examples can be seen on the link bewlow
//
// Link of algorithm review: https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/
package Strings;
public class ZFunction {
private String string;
public ZFunction(String string){
this.string = string;
}
public int[] getArray(){
int length = string.length();
int[] z = new int[length];
int l = 0, r = 0;
for (int i=0; i<length; i++){
if (i > l && i <= r){
z[i] = Math.min(z[i - l], r - i + 1);
}
while (i + z[i] < length && string.charAt(z[i]) == string.charAt(i + z[i])){
z[i]++;
}
if (i + z[i] > r){
l = i;
r = i + z[i] - 1;
}
}
return z;
}
}