From 6e7a326f75e6d74b22ce14ceca5f9a137e6bde43 Mon Sep 17 00:00:00 2001 From: Sombit Bose Date: Wed, 22 Jul 2020 23:29:09 +0530 Subject: [PATCH] Revert "z function added" --- Strings/ZFunction.java | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 Strings/ZFunction.java diff --git a/Strings/ZFunction.java b/Strings/ZFunction.java deleted file mode 100644 index f9ca97d6b..000000000 --- a/Strings/ZFunction.java +++ /dev/null @@ -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 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; - } -}