You are viewing a single comment's thread. Return to all comments →
Java O(n m)
public static int commonChild(String s1, String s2) { int n = s1.length(); int m = s2.length(); int[][] dp = new int[n+1][m+1]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s1.charAt(i) == s2.charAt(j)) { dp[i+1][j+1] = dp[i][j] + 1; } else { dp[i+1][j+1] = Math.max(dp[i+1][j], dp[i][j+1]); } } } return dp[n][m]; }
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 →
Java O(n m)