标签:
代码:
1 #include<iostream> 2 3 using namespace std; 4 5 int lengthOfLongestSubString(string s) 6 { 7 if (s.length() == 0) 8 return 0; 9 int max = 1; 10 int j = 0; 11 for (int i = 1; i < s.length(); i++) 12 { 13 int t = s.find(s[i], j); 14 if (t == i) 15 { 16 int temp = i - j + 1; 17 if (temp > max) 18 max = temp; 19 } 20 else if (t < i) 21 { 22 j = t + 1; 23 } 24 } 25 return max; 26 } 27 28 int main() 29 { 30 string s = "abcabcbb"; 31 cout << lengthOfLongestSubString(s) << endl; 32 }
leetcode Longest Substring Without Repeating Characters
标签:
原文地址:http://www.cnblogs.com/chaiwentao/p/4313937.html