LengthOfLongestSubstring in C# using Sliding window approach. O(n)
\n# Approach\n Describe your approach to solving the problem. \nThis solution uses a sliding window approach to find the longest\nsubstring without repeating ch
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis solution uses a sliding window approach to find the longest\nsubstring without repeating characters.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(min(n, m))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n    public int LengthOfLongestSubstring(string s) {\n        var charSet = new HashSet<char>();\n        int left = 0, right = 0, maxLength = 0;\n        while(right < s.Length)\n        {\n            if (!charSet.Contains(s[right]))\n            {\n                charSet.Add(s[right]);\n                right++;\n                maxLength = Math.Max(maxLength, charSet.Count);\n            }\n            else\n            {\n                charSet.Remove(s[left]);\n                left++;\n            }\n        }\n        return maxLength;\n    }\n}\n```
['C#']