Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
int fun(string s){ int n = s.length(); bool flag[256]; memset(flag, true, sizeof(flag)); int result = 0; int start = 0; for (int i = 0; i < n; i++) { if (flag[s[i]]) { flag[s[i]] = false; } else { result = max(result, i-start); for (int j = start; j < i; j++) { if (s[j] == s[i]) { start = j+1; break; } else { flag[s[j]] = true; } } } } result = max(result, n-start); return result;}
新闻热点
疑难解答