首页 > 学院 > 开发设计 > 正文

Longest Substring Without Repeating Characters

2019-11-08 18:23:25
字体:
来源:转载
供稿:网友

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.

int fun(string s){	int n = s.length();	bool flag[256];	memset(flag, true, sizeof(flag));	int result = 0;	int start = 0;	for (int i = 0; i < n; i++)	{		if (flag[s[i]])		{			flag[s[i]] = false;		}		else		{			result = max(result, i-start);			for (int j = start; j < i; j++)			{				if (s[j] == s[i])				{					start = j+1;					break;				}				else				{					flag[s[j]] = true;				}			}		}	}	result = max(result, n-start);	return result;}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表