Longest Substring Without Repeating Characters

#include <string>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int lengthOfLongestSubstring(string s) {
    vector<int> temp(256, -1);
    int max_l = 0;
    int begin = 0;
    for (int i = 0; i < s.size(); i++) {
        begin = max(temp[s[i]]+1, begin);
        temp[s[i]] = i;
        max_l = max(max_l, i - begin + 1);
    }
    return max_l;
}
int main() {
    string b = "aabc";
    string a = "0";
    int res=lengthOfLongestSubstring(b);
}

posted @ 2016-03-14 22:11  HUSTLX  阅读(136)  评论(0编辑  收藏  举报