class Solution { public: int lengthOfLongestSubstring(string s) { if (s.size() == 0){ return 0; } int ret = 0; int tlength = 1; bool flag = false; //匹配标记 int b = 0; // 边界标记 const char* p = s.c_str(); for(int i=1;i<s.size();i++){ for(int j =b;j<i;j++){ if(p[i] == p[j]){ flag = true; b = j+1; if (tlength > ret){ ret = tlength; } tlength = i - j; break; } } if (!flag){ tlength = tlength + 1; } flag = false; } if (tlength > ret){ ret = tlength; } return ret; } };