Guest User

Untitled

a guest
Nov 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. int longestCommonSubstring(string &A, string &B) {
  2. int LCSuff[A.length()+1][B.length()+1];
  3. int result = 0; // To store length of the longest common substring
  4.  
  5. /* Following steps build LCSuff[m+1][n+1] in bottom up fashion. */
  6. for (int i=0; i<=A.length(); i++) {
  7. for (int j=0; j<=B.length(); j++) {
  8. if (i == 0 || j == 0) {
  9. LCSuff[i][j] = 0;
  10. } else if (A[i-1] == B[j-1]) {
  11. LCSuff[i][j] = LCSuff[i-1][j-1] + 1;
  12. result = max(result, LCSuff[i][j]);
  13. } else {
  14. LCSuff[i][j] = 0;
  15. }
  16. }
  17. }
  18.  
  19. return result;
  20. }
Add Comment
Please, Sign In to add comment