solution.cpp 437 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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;
	}
}