首页 > 其他 > 详细

3 Longest Substring Without Repeating Characters

时间:2015-07-10 09:32:37      阅读:209      评论:0      收藏:0      [点我收藏+]

3 Longest Substring Without Repeating Characters

链接: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.

Hide Tags Hash Table Two Pointers String

求给出字符串中的不重复的最大子串长度。

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int result=0,n;
        string temp="";
        for(int i=0;i<s.length();i++)
        {
            n=temp.find(s[i]);
            if(n<0)
              temp+=s[i];
            else
           {
               if(result<temp.size())
                   result=temp.size();

               temp=temp.substr(n+1)+s[i];
           }
        }
         if(result<temp.size())
                   result=temp.size();
        return result;
    }
};

版权声明:本文为博主原创文章,未经博主允许不得转载。

3 Longest Substring Without Repeating Characters

原文:http://blog.csdn.net/efergrehbtrj/article/details/46822335

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