spider68

Longest Substring Without Repeating Characters.cpp

May 6th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. int SubsequenceLength (string s)
  2. {
  3.     int mp[26]={0};
  4.     int i,j=0;
  5.     int cnt=0,maxx=0;
  6.     for(i=1;i<=s.length();i++)
  7.     {
  8.        
  9.         if(mp[s[i-1]-'a']>j)
  10.         {
  11.             j=mp[s[i-1]-'a'];
  12.         }
  13.         mp[s[i-1]-'a']=i;
  14.         maxx=maxx>(i-j)?maxx:(i-j);
  15.     }
  16.     return maxx;
  17. }
Add Comment
Please, Sign In to add comment