This commit is contained in:
Electrominch
2022-10-11 01:45:16 +03:00
parent c019e8856c
commit 02afed9c4c
34 changed files with 691 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_3._Longest_Substring_Without_Repeating_Characters</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
namespace _3._Longest_Substring_Without_Repeating_Characters;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(new Solution().LengthOfLongestSubstring("dvdf"));
}
}

View File

@@ -0,0 +1,24 @@
namespace _3._Longest_Substring_Without_Repeating_Characters;
public class Solution
{
public int LengthOfLongestSubstring(string s)
{
int max = 0;
Dictionary<char, int> dict = new Dictionary<char, int>();
for(int i = 0; i < s.Length; i++)
{
char c = s[i];
if(dict.ContainsKey(c))
{
max = Math.Max(max, dict.Count);
i = dict[c];
dict.Clear();
}
else
dict.Add(c, i);
}
max = Math.Max(max, dict.Count);
return max;
}
}