2
public String shortestCommonSupersequence(String str1, String str2) {5
int[][] dp = new int[m + 1][n + 1];6
for (int i = 1; i < m + 1; i++) {7
for (int j = 1; j < n + 1; j++) {8
if (str1.charAt(i - 1) == str2.charAt(j - 1)) {9
dp[i][j] = 1 + dp[i - 1][j - 1];11
dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);17
while (i > 0 && j > 0) {18
if (str1.charAt(i - 1) == str2.charAt(j - 1)) {19
res = str1.charAt(i - 1) + res;22
} else if (dp[i - 1][j] > dp[i][j - 1]) {23
res = str1.charAt(i - 1) + res;26
res = str2.charAt(j - 1) + res;31
res = str1.charAt(i - 1) + res;35
res = str2.charAt(j - 1) + res;