1 class Solution {
2 public:
3 int lengthOfLongestSubstring(
string s) {
4 int n =
s.length();
5 int i =
0, j =
0;
6 int maxLen =
0;
7 bool exist[
256] = {
false };
8 while (j <
n) {
9 if (exist[s[j]]) {
10 maxLen = max(maxLen, j-
i);
11 while (s[i] !=
s[j]){
12 exist[s[i]] =
false;
13 i++
;
14 }
15 i++
;
16 j++
;
17 }
else {
18 exist[s[j]] =
true;
19 j++
;
20 }
21 }
22 maxLen = max(maxLen, n-
i);
23 return maxLen;
24 }
25 };
转载于:https://www.cnblogs.com/tanghulu321/archive/2013/05/14/3077038.html
相关资源:LeetCode3 Longest Substring Without Repeating Characters