Skip to content

Commit a983a15

Browse files
committed
description added and also link to the algorithm review
1 parent 7a4d6b2 commit a983a15

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Strings/ZFunction.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
// Initialisation of strings algorithm Z function
2+
// detailed review and proper examples can be seen on the link bewlow
3+
//
4+
// Link of algorithm review: https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/
15
package Strings;
26

37
public class ZFunction {
4-
private String s;
8+
private String string;
59

6-
public ZFunction(String s){
7-
this.s = s;
10+
public ZFunction(String string){
11+
this.string = string;
812
}
913

1014
public int[] getArray(){
11-
int length = s.length();
15+
int length = string.length();
1216
int[] z = new int[length];
1317
int l = 0, r = 0;
1418
for (int i=0; i<length; i++){
1519
if (i > l && i <= r){
1620
z[i] = Math.min(z[i - l], r - i + 1);
1721
}
18-
while (i + z[i] < length && s.charAt(z[i]) == s.charAt(i + z[i])){
22+
while (i + z[i] < length && string.charAt(z[i]) == string.charAt(i + z[i])){
1923
z[i]++;
2024
}
2125
if (i + z[i] > r){

0 commit comments

Comments
 (0)