leetcode3+头条三面面试题

https://leetcode.com/problems/longest-substring-without-repeating-characters/

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int num=0, i=0, j=0,index=0,len=0;
        len = s.length();
        if(len==0) return 0;
        if(len==1) return 1;
        for(int i=1; i=index;j--){//这里的剪肢很重要
                if(s[j]==s[i]){
                    index = j+1;
                    break;
                }
                else{
                    num = max(num, i-j+1);
                }
            }
        }
        return  max(num,1);
    }
};

 

你可能感兴趣的:(进阶LC)