longest substring without repeating character leetcode c++

来源:互联网 发布:学生打人知乎 编辑:程序博客网 时间:2024/05/16 02:42

this problem broaden its test set,so that we should use sign[xxxx]-'a' two record;

and when we calculate the length, we should test j-i+1;

class Solution {public:    int lengthOfLongestSubstring(string s) {            int sign[300]={0};    int i = 0;    int j = 0;    int max = 0;    for(i = 0,j = 0;j<s.length();j++)    {        while(sign[s[j]-' '] == 1)            {                sign[s[i]-' '] = 0;                i++;            }         sign[s[j]-' '] = 1;        if(j-i +1> max)            max = j-i+1;    }    return max;       }};


0 0