求助|力扣第三题我纯萌新,思路应该没错,为什么会执行出错呢
519
2023.12.25
发布于 未知归属地
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int i=0,j=1,k,max,n=s.size();
        vector<int> a;
        while(j<n){
            while(s[i]!=s[j]){j++;}
            k = j-i;
            a.push_back(k);
            i++;
        } 
        max = *max_element(a.begin(),a.end());
        return max;
    }
};

题目是给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
如输入: s = "abcabcbb"
输出: 3
解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。

评论 (2)