```
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.empty()) return 0;
int p1 = 0, p2 = 1;
int maxLen = p2 - p1;
for(; p2 < s.length(); ++p2) {
int i = p1;
for(; i < p2; ++i) {
if(s[i] == s[p2]) {
p1 = i + 1;
break;
}
}
maxLen = max(maxLen, p2 - p1 + 1);
}
return maxLen;
}
};
```