leetcode Longest Substring Without Repeating Characters

class Solution {
public:
    int lengthOfLongestSubstring(string s) 
    {
       int maxlen=0;
       if(s=="")return 0;
       vector<int>v(s.size(),1);
       int i;
       for(i=1;i<s.size();i++)
       {
           for(int j=1;j<=v[i-1];j++)
           {
               if(s[i]!=s[i-j])
               v[i]++;
               else 
               {
                   v[i]=j;
                   break;
               }
           }
       }
       int max=1;
       for(i=0;i<v.size();i++)
       {
           if(v[i]>max)max=v[i];
       }
       return max;
    }
};

 

posted @ 2013-05-22 21:51  代码改变未来  阅读(151)  评论(0编辑  收藏  举报