c++(O(n)):
class Solution {
public:
int minimumDeleteSum(string s1, string s2) {
int m = s1.size(), n = s2.size();
vector<int> dp(n+1, 0);
for (int j = 1; j <= n; j++)
dp[j] = dp[j-1]+s2[j-1];
for (int i = 1; i <= m; i++) {
int t1 = dp[0];
dp[0] += s1[i-1];
for (int j = 1; j <= n; j++) {
int t2 = dp[j];
dp[j] = s1[i-1] == s2[j-1]? t1:min(dp[j]+s1[i-1], dp[j-1]+s2[j-1]);
t1 = t2;
}
}
return dp[n];
}
};