Skip to content

Instantly share code, notes, and snippets.

@Masud-Parves
Created January 4, 2020 19:06
Show Gist options
  • Save Masud-Parves/61775f22b37677181144146ab91ff2b6 to your computer and use it in GitHub Desktop.
Save Masud-Parves/61775f22b37677181144146ab91ff2b6 to your computer and use it in GitHub Desktop.
z_algorithm( Brute Force/ Trivial algorithm )
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