首页 > 其他 > 详细

Longest Substring Without Repeating Characters

时间:2015-10-29 06:18:44      阅读:246      评论:0      收藏:0      [点我收藏+]

问题链接: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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!