标签:
问题链接:https://leetcode.com/problems/longest-substring-without-repeating-characters/
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
20ms
class Solution { public: int lengthOfLongestSubstring(string s) { string::iterator i = s.begin(), f = s.begin(), t; int max = 0;; for (;i != s.end();++i) { t= find(f, i, *i); if (t != i) { f = t + 1; } if ((i - f + 1) > max) max = i -f + 1; } return max; } };
Longest Substring Without Repeating Characters
标签:
原文地址:http://my.oschina.net/u/2313065/blog/523356