File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 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/
15package Strings ;
26
37public 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 ){
You can’t perform that action at this time.
0 commit comments