bexp
11/6/2017 - 8:49 PM

longest substring

int longest_substring(const string& str1, const string& str2) {
    
    int n = str1.length();
    int m = str2.length();
    
    int suffix[n + 1][m + 1] = {};
    
    int result = 0;
    
    
    for (int i = 0; i <= n;i++) {
        for (int j = 0; j <=m; j++) {
            
            if (i == 0 || j == 0) {
                suffix[i][j] = 0;   
                
            } else if (str1.at(i - 1) == str2.at(j - 1)) {
                suffix[i][j] = suffix[i - 1][j - 1] + 1;
                result = max(result, suffix[i][j]); 
            } else {
                suffix[i][j] = 0;
            }                    
       }
    }
    
 
   
    return result;
    
}