码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode Longest Substring Without Repeating Characters

时间:2015-03-04 18:52:52      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

代码:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!