You are viewing a single comment's thread. Return to all comments →
C++ Based on this article: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
int commonChild(string s1, string s2) { int n = s1.length(), m = s2.length(); vector<vector<int>> arr(n+1,vector<int>(m+1)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(s1[i-1] == s2[j-1]){ arr[i][j] = arr[i-1][j-1] + 1; } else{ arr[i][j] = max(arr[i-1][j], arr[i][j-1]); } } } return arr[m][n]; }
Seems like cookies are disabled on this browser, please enable them to open this website
Common Child
You are viewing a single comment's thread. Return to all comments →
C++ Based on this article: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem