[LeetCode]——Longest Substring Without Repeating Characters

来源:互联网 发布:魔法提琴手 知乎 编辑:程序博客网 时间:2024/06/06 07:22

作为模式识别的图像狗,越发觉得毕业找工作还是得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;    }};
0 0
原创粉丝点击