Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2eb4f3a commit 1ceb60fCopy full SHA for 1ceb60f
3-Longest-Substring.cs
@@ -0,0 +1,28 @@
1
+using System;
2
+namespace AlgoPractice
3
+{
4
+ public class Solution
5
+ {
6
+ public int LengthOfLongestSubstring(string s)
7
8
+ var set = new HashSet<char>();
9
+ var maxLength = 0;
10
+ var left = 0;
11
+ var right = 0;
12
+ while(right < s.Length)
13
14
+ var currentChar = s[right];
15
+ while (set.Contains(currentChar) && left < s.Length)
16
17
+ set.Remove(s[left++]);
18
+ }
19
+ set.Add(currentChar);
20
+ right++;
21
+ var length = right - left;
22
+ maxLength = Math.Max(length, maxLength);
23
24
+ return maxLength;
25
26
27
+}
28
+
0 commit comments