Skip to content

Commit

Permalink
Create longest-substring-without-repeating-characters.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhieu-it authored May 6, 2024
1 parent 61ef560 commit 606614b
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Solution {
public int LengthOfLongestSubstring(string s) {
var set = new HashSet<char>();
int i = 0, longest = 0;
for (int j = 0; j < s.Length; ++j) {
char currentChar = s[j];
while (set.Contains(currentChar)) {
set.Remove(s[i++]);
}
set.Add(currentChar);
longest = Math.Max(longest, j - i + 1);
}
return longest;
}
}

0 comments on commit 606614b

Please sign in to comment.