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

003.Longest Substring Without Repeating Characters

时间:2016-10-15 09:24:30      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

 1 class Solution {
 2 public:
 3     int lengthOfLongestSubstring(string s) {
 4         const int ASCII_MAX = 256;
 5         int last[ASCII_MAX];
 6         memset(last, -1, sizeof(last));
 7         int startPos = 0; int len = 0;
 8         for (int i = 0; i < s.size(); ++i) {
 9             if (last[s[i]] >= startPos) {
10                 len = max(len, i - startPos);
11                 startPos = last[s[i]] + 1;
12             }
13             last[s[i]] = i;
14         }
15         return max(len, static_cast<int>(s.size()) - startPos);
16     }
17 };

 

003.Longest Substring Without Repeating Characters

标签:

原文地址:http://www.cnblogs.com/shadowwalker9/p/5962711.html

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