LeetCode

题目描述:

 找出一个字符串中,不含有相同字符的最长子串。

做法:

 开一个200的bool数组标记,Ascll码 是否已经出现过了。遍历即可。

AC代码:

class Solution {
      int a[200];
public:
    int lengthOfLongestSubstring(string s) {
 
        int l = 0;int r =0;
        int vmax = 0;
        while(s[r]){
            a[s[r]]++;
            while(a[s[r]]==2){
                a[s[l]]--;
                l++;
            }
            vmax = max(vmax,r-l+1);
            r++;
        }
        return vmax;
    }
};
983 / 983 test cases passed.
Status: Accepted
Runtime: 22 ms
原文地址:https://www.cnblogs.com/clover-xuqi/p/7154773.html