[LeetCode]——Longest Substring Without Repeating Characters

作为模式识别的图像狗,越发觉得毕业找工作还是得coding!
痛定思痛,入了leetcode的深坑!
在提交了无数次以后,Accepted终于向俺招手了~
虽说复杂度高了点,但是作为一个学渣,能看到Accepted这辈子也值了!

class Solution {
public:
       int lengthOfLongestSubstring(string s) {
        string::size_type n=s.size();
        int max=0;
       for(string::size_type i=0;i!=n;i++)
       {    
           vector<int> a(256);
           int temp=0;
           for(string::size_type j=i;j!=n;j++)
                {  
                    if(a[s[j]]==0)
                       { 
                         a[s[j]]++;
                         temp=j-i+1;
                          if(temp>max)
                            max=temp;
                    }
                    else
                       {    
                                break;
                       }
                    if(j==n)
                        return temp;
                } 

       }
       return max;
    }
};

你可能感兴趣的:(Coding,substring)