LeetCode之Longest Substring Without Repeating Characters

来源:互联网 发布:三国杀diy软件 编辑:程序博客网 时间:2024/05/28 22:10
class Solution {public:    int lengthOfLongestSubstring(string s) {        vector<int> loc(256, -1);        int start = -1, res(0);        for(int i = 0; i < s.size(); ++i){            if(loc[s[i]] > start) start = loc[s[i]];            if(i - start > res) res = i - start;            loc[s[i]] = i;        }        return res;    }};

0 0