problem 3

This commit is contained in:
Buduf 2022-04-14 13:35:04 +02:00
parent 35a2375f7e
commit 99a222c319

View File

@ -0,0 +1,30 @@
public class Solution {
public int LengthOfLongestSubstring(string s) {
int max = 0;
int n = 0;
for (int i = 0; i < s.Length; i++)
{
n++;
if (n > 1)
{
n -= FindDuplicateCharacter(s.Substring(i - n + 1, n)) + 1;
}
if (n > max) {
max = n;
}
}
return max;
}
public int FindDuplicateCharacter(string s) {
char last = s[s.Length - 1];
for (int i = 0; i < s.Length - 1; i++)
{
if (s[i] == last)
{
return i;
}
}
return -1;
}
}