3. 无重复字符的最长子串
给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
public class Solution {
public int LengthOfLongestSubstring(string s) {
string maxString = "";//最长的字符串
string currentString = "";//用于记录现在的字符串
for (int i = 0; i < s.Length; i++)
{
currentString = currentString + s[i];
for (int j = i; j < s.Length - 1; j++)
{
int myindex = currentString.IndexOf(s[j + 1]);
if (myindex == -1)//不存在
{
currentString = currentString + s[j + 1];
}
else
{
break;
}
}
if (currentString.Length > maxString.Length)
{
maxString = currentString;
currentString = "";
}
currentString = "";
}
Console.WriteLine(maxString);
return maxString.Length;
}
}