We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int n=s1.size();
int m=s2.size();
vector<int>pre(m+2),cur(m+2); //pre is previous row, cur is current row
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
if(i==0 or j==0)pre[j]=cur[j]=0;
else if(s1[i-1]==s2[j-1]) cur[j]=pre[j-1]+1;
else cur[j]=max(pre[j],cur[j-1]);
}
pre=cur;
}
return cur[m];
}
Cookie support is required to access HackerRank
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 →
Easiest ||C++||LCS
int commonChild(string s1, string s2) {
}