1 class Solution {
2 public:
3 int lengthOfLongestSubstring(string s) {
4 int mark[256] = { 0 };
5 int begin = 0;
6 int end = 0;
7 int ret_max = 0;
8 while (begin<=end &&begin <s.length() && end<s.length())
9 {
10 char ch = s[end];
11 if (mark[ch] == 0){
12 mark[ch]++;
13 end++;
14 }else{
15 ch = s[begin];
16 mark[ch]--;
17 begin++;
18 }
19 ret_max = end - begin > ret_max ? end - begin : ret_max;
20 }
21 return ret_max;
22 }
23 };
24