Created
January 4, 2020 19:06
-
-
Save Masud-Parves/61775f22b37677181144146ab91ff2b6 to your computer and use it in GitHub Desktop.
z_algorithm( Brute Force/ Trivial algorithm )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void z_algo(string s){ | |
int n = (int) s.length(); | |
vector<int> z(n); | |
z[0] = 0; // z[0] = 0 or z[0] = n according to problem statement; | |
for(int i=1; i<n; ++i){ | |
while (i + z[i] < n && s[z[i]] == s[i + z[i]]){ | |
++z[i]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment