Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int longestStrChain(vector<string>& words) {
- sort(words.begin(),words.end(),[](string a,string b){return a.length()<b.length();});
- int sum=0;
- map<string,int>dp;
- int i,j;
- for(string s:words)
- {
- for(i=0;i<s.length();i++)
- {
- dp[s]=max(1+dp[s.substr(0,i)+s.substr(i+1)],dp[s]);
- }
- sum=max(sum,dp[s]);
- }
- return sum;
- }
Add Comment
Please, Sign In to add comment