Longest Substring Without Repeating Characters 7 lines with c++ in 12ms

 1 class Solution {
 2 public:
 3     int lengthOfLongestSubstring(string s) {
 4         int m = 0;
 5         for (int i = 0, len = s.length(), l = 0, p[256] = { 0 }, c; i < len; ) {
 6             l = max(l, p[c = s.at(i), c]);
 7             p[c] = ++i;
 8             m = max(m, i - l);
 9         }
10         return m;
11     }
12 };

 

posted @ 2015-07-10 01:33  国超  阅读(189)  评论(0编辑  收藏  举报