import java.util.*;
public class Solution {
/**
* longest common subsequence
* @param s1 string字符串 the string
* @param s2 string字符串 the string
* @return string字符串
*/
public String LCS (String s1, String s2) {
// write code here
int m = s1.length();
int n = s2.length();
if(m == 0 || n == 0) {
return "-1";
}
char[] arr1 = s1.toCharArray();
char[] arr2 = s2.toCharArray();
String[][] dp = new String[m + 1][n + 1];
for(int i = 0; i < dp.length; i++) {
dp[i][0] = "";
}
for(int i = 0; i < dp[0].length; i++) {
dp[0][i] = "";
}
int maxVal = 0, lastI = -1, lastJ = -1;
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
if(arr1[i] == arr2[j]) {
dp[i + 1][j + 1] = dp[i][j] + arr1[i];
if(dp[i + 1][j + 1].length() > maxVal) {
maxVal = dp[i + 1][j + 1].length();
lastI = i + 1;
lastJ = j + 1;
}
} else {
if(dp[i][j + 1].length() > dp[i + 1][j].length()) {
dp[i + 1][j + 1] = dp[i][j + 1];
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
}
}
}
}
if(maxVal == 0) {
return "-1";
}
return dp[lastI][lastJ];
}
}