leetcode 3 Longest Substring Without Repeating Characters

2018-06-04 11:37:37 浏览数 (1)

代码语言:javascript复制
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int m[256] = {0}, res = 0, left = 0;
        for (int i = 0; i < s.size();   i) {
            if (m[s[i]] == 0 || m[s[i]] < left) {
                res = max(res, i - left   1);
            } else {
                left = m[s[i]];
            }
            m[s[i]] = i   1;
        }
        return res;
    }
};

0 人点赞