Guest User

Untitled

a guest
Nov 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. int longestCommonSubstring(string &A, string &B) {
  2. // write your code here
  3. if(A.length() == 0 || B.length() == 0) {
  4. return 0;
  5. }
  6.  
  7. int lcs = 0, cs = 0;
  8. for(unsigned i=0; i<A.length(); i++) {
  9. for(unsigned j=0; j<B.length(); j++) {
  10. cs = 0;
  11. while(i+cs < A.length() && j+cs < B.length() && A[i+cs] == B[j+cs]) {
  12. cs += 1;
  13. }
  14. lcs = max(lcs, cs);
  15. }
  16. }
  17.  
  18. return lcs;
  19. }
Add Comment
Please, Sign In to add comment