class Solution {
// idea: Find the length of LCS and remove the length from original string
public int minDeletions
(String s
) { String s2
= new StringBuilder
(s
).
reverse().
toString(); int n = s.length();
int m = s2.length();
int[][] t = new int[n+1][m+1];
for(int i=0; i<n+1; i++)
{
for(int j=0; j<m+1; j++)
{
if(i == 0 || j == 0)
t[i][j] = 0;
}
}
for(int i=1; i<n+1; i++)
{
for(int j=1; j<m+1; j++)
{
if(s.charAt(i-1) == s2.charAt(j-1))
t[i][j] = 1 + t[i-1][j-1];
else
t
[i
][j
] = Math.
max(t
[i
-1][j
], t
[i
][j
-1]); }
}
int lcsLength = t[n][m];
return (n-lcsLength);
}
}
// aebcbda
// adbcbea
// abcba -> lcs
// aba
// aba