class Solution { public: int lengthOfLongestSubstring(String s) { int front = 0, rear = 0; int temp = 0; int lengthmax = 0; for (rear = 0; rear < s.length(); rear++) { for (front = temp; front < rear; front++) { if (s.charAt(front) == s.charAt(rear)) { temp = front + 1; break; } } if ((rear - temp + 1) > lengthmax) { lengthmax = (rear - temp + 1); } } return lengthmax; } }